home *** CD-ROM | disk | FTP | other *** search
/ Software of the Month Club 2000 October / Software of the Month - Ultimate Collection Shareware 277.iso / pc / PROGRAMS / UTILITY / WINLINUX / DATA1.CAB / programs_-_usrdoc / PCMCIA-C.{1O / PCMCIA-P.{_1 < prev    next >
Text File  |  1999-09-17  |  141KB  |  3,854 lines

  1.   Linux PCMCIA Programmer's Guide
  2.   David Hinds, dhinds@hyper.stanford.edu.
  3.   v2.12, 1998/10/02 09:15:21
  4.  
  5.   This document describes how to write kernel device drivers for the
  6.   Linux PCMCIA Card Services interface.  It also describes how to write
  7.   user-mode utilities for communicating with Card Services.  The latest
  8.   version of this document can always be found at <ftp://hyper.stan-
  9.   ford.edu/pub/pcmcia/doc>.  An HTML version is at <http://hyper.stan-
  10.   ford.edu/HyperNews/get/pcmcia/home.html>.
  11.   ______________________________________________________________________
  12.  
  13.   Table of Contents:
  14.  
  15.   1.      Introduction
  16.  
  17.   1.1.    Copyright notice and disclaimer
  18.  
  19.   1.2.    Acknowledgements
  20.  
  21.   2.      Basic Concepts
  22.  
  23.   2.1.    The socket interface
  24.  
  25.   2.2.    The socket controller
  26.  
  27.   3.      Card Services subfunction descriptions
  28.  
  29.   3.1.    Client management functions
  30.  
  31.   3.1.1.  RegisterClient
  32.  
  33.   3.1.2.  DeregisterClient
  34.  
  35.   3.1.3.  SetEventMask
  36.  
  37.   3.1.4.  BindDevice
  38.  
  39.   3.2.    Socket state control
  40.  
  41.   3.2.1.  GetStatus
  42.  
  43.   3.2.2.  ResetCard
  44.  
  45.   3.2.3.  SuspendCard
  46.  
  47.   3.2.4.  ResumeCard
  48.  
  49.   3.2.5.  EjectCard
  50.  
  51.   3.2.6.  InsertCard
  52.  
  53.   3.3.    IO card configuration calls
  54.  
  55.   3.3.1.  RequestIO
  56.  
  57.   3.3.2.  ReleaseIO
  58.  
  59.   3.3.3.  RequestIRQ
  60.  
  61.   3.3.4.  ReleaseIRQ
  62.  
  63.   3.3.5.  RequestConfiguration
  64.  
  65.   3.3.6.  ModifyConfiguration
  66.  
  67.   3.3.7.  ReleaseConfiguration
  68.  
  69.   3.3.8.  GetConfigurationInfo
  70.  
  71.   3.4.    Card Information Structure (CIS) calls
  72.  
  73.   3.4.1.  GetFirstTuple, GetNextTuple
  74.  
  75.   3.4.2.  GetTupleData
  76.  
  77.   3.4.3.  ParseTuple
  78.  
  79.   3.4.4.  ValidateCIS
  80.  
  81.   3.4.5.  ReplaceCIS
  82.  
  83.   3.5.    Memory window control
  84.  
  85.   3.5.1.  RequestWindow
  86.  
  87.   3.5.2.  ModifyWindow
  88.  
  89.   3.5.3.  MapMemPage
  90.  
  91.   3.5.4.  ReleaseWindow
  92.  
  93.   3.6.    Bulk Memory Services
  94.  
  95.   3.6.1.  RegisterMTD
  96.  
  97.   3.6.2.  GetFirstRegion, GetNextRegion
  98.  
  99.   3.6.3.  OpenMemory
  100.  
  101.   3.6.4.  CloseMemory
  102.  
  103.   3.6.5.  ReadMemory, WriteMemory
  104.  
  105.   3.6.6.  RegisterEraseQueue
  106.  
  107.   3.6.7.  DeregisterEraseQueue
  108.  
  109.   3.6.8.  CheckEraseQueue
  110.  
  111.   3.7.    Miscellaneous calls
  112.  
  113.   3.7.1.  GetCardServicesInfo
  114.  
  115.   3.7.2.  AccessConfigurationRegister
  116.  
  117.   3.7.3.  AdjustResourceInfo
  118.  
  119.   3.7.4.  ReportError
  120.  
  121.   4.      Card Information Structure Definitions
  122.  
  123.   4.1.    CIS Tuple Definitions
  124.  
  125.   4.1.1.  CISTPL_CHECKSUM
  126.  
  127.   4.1.2.  CISTPL_LONGLINK_A, CISTPL_LONGLINK_C, CISTPL_LINKTARGET,
  128.   CISTPL_NOLINK
  129.  
  130.   4.1.3.  CISTPL_LONGLINK_MFC
  131.  
  132.   4.1.4.  CISTPL_DEVICE, CISTPL_DEVICE_A
  133.  
  134.   4.1.5.  CISTPL_VERS_1
  135.  
  136.   4.1.6.  CISTPL_ALTSTR
  137.  
  138.   4.1.7.  CISTPL_JEDEC_C, CISTPL_JEDEC_A
  139.  
  140.   4.1.8.  CISTPL_CONFIG, CISTPL_CONFIG_CB
  141.  
  142.   4.1.9.  CISTPL_BAR
  143.  
  144.   4.1.10. CISTPL_CFTABLE_ENTRY
  145.  
  146.   4.1.11. CISTPL_CFTABLE_ENTRY_CB
  147.  
  148.   4.1.12. CISTPL_MANFID
  149.  
  150.   4.1.13. CISTPL_FUNCID
  151.  
  152.   4.1.14. CISTPL_DEVICE_GEO
  153.  
  154.   4.1.15. CISTPL_VERS_2
  155.  
  156.   4.1.16. CISTPL_ORG
  157.  
  158.   4.2.    CIS configuration register definitions
  159.  
  160.   4.2.1.  Configuration Option Register
  161.  
  162.   4.2.2.  Card Configuration and Status Register
  163.  
  164.   4.2.3.  Pin Replacement Register
  165.  
  166.   4.2.4.  Socket and Copy Register
  167.  
  168.   4.2.5.  Extended Status Register
  169.  
  170.   4.2.6.  IO Base and Size Registers
  171.  
  172.   5.      Card Services Event Handling
  173.  
  174.   5.1.    Event handler operations
  175.  
  176.   5.2.    Event descriptions
  177.  
  178.   5.3.    Client driver event handling responsibilities
  179.  
  180.   6.      Memory Technology Drivers
  181.  
  182.   6.1.    MTD request handling
  183.  
  184.   6.2.    MTD helper functions
  185.  
  186.   6.2.1.  MTDRequestWindow, MTDReleaseWindow
  187.  
  188.   6.2.2.  MTDModifyWindow
  189.  
  190.   6.2.3.  MTDSetVpp
  191.  
  192.   6.2.4.  MTDRDYMask
  193.  
  194.   7.      Driver Services interface
  195.  
  196.   7.1.    Interface to other client drivers
  197.  
  198.   7.1.1.  The dev_link_t structure
  199.  
  200.   7.1.2.  register_pccard_driver
  201.  
  202.   7.1.3.  unregister_pccard_driver
  203.  
  204.   7.2.    The CardBus client interface
  205.  
  206.   7.2.1.  register_driver
  207.  
  208.   7.2.2.  unregister_driver
  209.  
  210.   7.2.3.  The driver_operations entry points
  211.  
  212.   7.3.    Interface to user mode utilities
  213.  
  214.   7.3.1.  Card Services event notifications
  215.  
  216.   7.3.2.  Ioctl descriptions
  217.  
  218.   8.      Anatomy of a Card Services Client Driver
  219.  
  220.   8.1.    Module initialization and cleanup
  221.  
  222.   8.2.    The *_attach() and *_detach() functions
  223.  
  224.   8.3.    The *_config() and *_release() functions
  225.  
  226.   8.4.    The client event handler
  227.  
  228.   8.5.    Locking and synchronization issues
  229.  
  230.   8.6.    Using existing Linux drivers to access PC Card devices
  231.  
  232.   9.      The socket driver layer
  233.  
  234.   9.1.    Card Services entry points for socket drivers
  235.  
  236.   9.2.    Services provided by the socket driver
  237.  
  238.   9.2.1.  SS_InquireSocket
  239.  
  240.   9.2.2.  SS_RegisterCallback
  241.  
  242.   9.2.3.  SS_GetStatus
  243.  
  244.   9.2.4.  SS_GetSocket, SS_SetSocket
  245.  
  246.   9.2.5.  SS_GetIOMap, SS_SetIOMap
  247.  
  248.   9.2.6.  SS_GetMemMap, SS_SetMemMap
  249.  
  250.   9.2.7.  SS_GetBridge, SS_SetBridge
  251.  
  252.   9.2.8.  SS_ProcSetup
  253.  
  254.   10.     Where to Go for More Information
  255.   ______________________________________________________________________
  256.  
  257.   11..  IInnttrroodduuccttiioonn
  258.  
  259.   The Linux kernel PCMCIA system has three main components.  At the
  260.   lowest level are the socket drivers.  Next is the Card Services
  261.   module.  Drivers for specific cards are layered on top of Card
  262.   Services.  One special Card Services client, called Driver Services,
  263.   provides a link betweek user level utility programs and the kernel
  264.   facilities.
  265.  
  266.   The socket driver layer is loosely based on the Socket Services API.
  267.   There are two socket driver modules.  The tcic module supports the
  268.   Databook TCIC-2 family of host controllers.  The i82365 module
  269.   supports the Intel i82365sl family and various Intel-compatible
  270.   controllers, including Cirrus, VLSI, Ricoh, and Vadem chips.  In
  271.   addition, the i82365 module implements support for CardBus controllers
  272.   that follow the ``Yenta'' register-level specification.
  273.  
  274.   Card Services is the largest single component of the package.  It
  275.   provides an API somewhat similar to DOS Card Services, adapted to a
  276.   Unix environment.  The Linux implementation was based in part on the
  277.   Solaris interface specification.  It is implemented in the pcmcia_core
  278.   module.  Most version 2.1 features are implemented, with some PC Card
  279.   95 features.
  280.  
  281.   The Driver Services layer implements a user mode pseudo-device for
  282.   accessing some Card Services functions from utility programs.  It is
  283.   responsible for keeping track of all client drivers, and for matching
  284.   up drivers with physical sockets.  It is implemented in the ds module.
  285.  
  286.   This document describes the kernel interface to the Card Services and
  287.   Driver Services modules, and the user interface to Driver Services.
  288.   It is intended for use by client device driver developers.  The Linux
  289.   PCMCIA-HOWTO describes how to install and use Linux PCMCIA support.
  290.   It is available from hyper.stanford.edu in /pub/pcmcia.
  291.  
  292.   11..11..  CCooppyyrriigghhtt nnoottiiccee aanndd ddiissccllaaiimmeerr
  293.  
  294.   Copyright (c) 1996, 1997 David A. Hinds
  295.  
  296.   This document may be reproduced or distributed in any form without my
  297.   prior permission.  Modified versions of this document, including
  298.   translations into other languages, may be freely distributed, provided
  299.   that they are clearly identified as such, and this copyright is
  300.   included intact.
  301.  
  302.   This document may be included in commercial distributions without my
  303.   prior consent.  While it is not required, I would like to be informed
  304.   of such usage.  If you intend to incorporate this document in a
  305.   published work, please contact me to make sure you have the latest
  306.   available version.
  307.  
  308.   This document is provided ``AS IS'', with no express or implied
  309.   warranties.  Use the information in this document at your own risk.
  310.  
  311.   11..22..  AAcckknnoowwlleeddggeemmeennttss
  312.  
  313.   I'd like to thank all the Linux users who have helped test and debug
  314.   this software, and who have helped with driver development.  I should
  315.   also thank Linus Torvalds, Donald Becker, Alan Cox, and Bjorn Ekwall
  316.   for Linux kernel development help.  I'm especially grateful to Michael
  317.   Bender for many helpful discussions about the Solaris implementation.
  318.  
  319.   22..  BBaassiicc CCoonncceeppttss
  320.  
  321.   22..11..  TThhee ssoocckkeett iinntteerrffaaccee
  322.  
  323.   The PC Card bus has two basic operating modes: ``memory-only'' and
  324.   ``memory and IO''.  The first mode was defined by the original Version
  325.   1.0 specification and only supports simple memory cards.  The second
  326.   mode, defined in Version 2.0, redefines a few of the memory card
  327.   control signals to support IO port addressing and IO interrupt
  328.   signalling.
  329.  
  330.   PC Card devices have two memory spaces: ``attribute memory'' and
  331.   ``common memory''.  The interface can address up to 16MB of each type
  332.   of memory.  Attribute memory is typically used for holding descriptive
  333.   information and configuration registers.  Common memory may include
  334.   the bulk storage of a memory card, or device buffers in the case of IO
  335.   cards.  All cards that are compliant with the version 2.0 PC Card
  336.   specification should have a Card Information Structure (or ``CIS'') in
  337.   attribute memory, which describes the card and how it should be
  338.   configured.
  339.  
  340.   Separate control signals allow cards to signal their operating status
  341.   to the host.  These signals include card detect, ready/busy, write
  342.   protect, battery low, and battery dead.
  343.  
  344.   The ``memory and IO'' interface mode allows cards to address up to 64K
  345.   of IO ports.  It also allows cards to signal IO interrupts, and routes
  346.   one card output to the host system's speaker.  In this mode, several
  347.   of the memory card control signals are unavailable because those pins
  348.   are used to carry the extra IO card signals.  On some cards, these
  349.   signals can instead be read from a special configuration register in
  350.   attribute memory, the ``Pin Replacement Register''.
  351.  
  352.   22..22..  TThhee ssoocckkeett ccoonnttrroolllleerr
  353.  
  354.   The socket controller serves as a bridge between PC Card devices and
  355.   the system bus.  There are several varieties of controllers, but all
  356.   share the same basic functionality.  The Socket Services software
  357.   layer takes care of all the details of how to program the host
  358.   controller.
  359.  
  360.   The socket controller has the job of mapping windows of addresses in
  361.   the host memory and IO spaces to windows of addresses in card space.
  362.   All supported controllers support at least four independent memory
  363.   windows and two IO windows per socket.
  364.  
  365.   Each memory window is defined by a base address in the host address
  366.   space, a base address in the card address space, and a window size.
  367.   Some controllers differ in their alignment rules for memory windows,
  368.   but all controllers will support windows whose size is at least 4K and
  369.   also a power of two, and where the base address is a multiple of the
  370.   window size.  Each window can be programmed to point to either
  371.   attribute or common memory.
  372.  
  373.   IO windows differ from memory windows in that host addresses that fall
  374.   within an IO window are not modified before they are passed on to an
  375.   IO card.  Effectively, the base addresses of the window in the host
  376.   and card address spaces are always equal.  IO windows also have no
  377.   alignment or size restrictions; an IO window can start and end on any
  378.   byte boundary in the 64K IO address space.
  379.  
  380.   The PC Card bus defines a single interrupt signal from the card to the
  381.   controller.  The controller then has the responsibility of steering
  382.   this interrupt to an appropriate interrupt request (``irq'') line.
  383.   All controllers support steering card IO interrupts to essentially any
  384.   free interrupt line.  Because steering happens in the controller, the
  385.   card itself is unaware of which interrupt it uses.
  386.   All PC Card controllers can generate interrupts in response to card
  387.   status changes.  These interrupts are distinct from the IO interrupts
  388.   generated by an IO card, and use a separate interrupt line.  Signals
  389.   that can generate interrupts include card detect, ready/busy, write
  390.   protect, battery low, and battery dead.
  391.  
  392.   33..  CCaarrdd SSeerrvviicceess ssuubbffuunnccttiioonn ddeessccrriippttiioonnss
  393.  
  394.   Card Services calls have the general form:
  395.  
  396.        #include "cs_types.h"
  397.        #include "cs.h"
  398.  
  399.        int CardServices(int subfunc, void *arg1, void *arg2, ...);
  400.  
  401.   Some Card Services functions require additional #include statements.
  402.   The particular subfunction determines the number of expected
  403.   arguments.  A return code of CS_SUCCESS indicates that a call
  404.   succeeded.  Other return codes indicate errors.
  405.  
  406.   33..11..  CClliieenntt mmaannaaggeemmeenntt ffuunnccttiioonnss
  407.  
  408.   Device drivers that use Card Services functions are called
  409.   ``clients''.  A device driver should use the RegisterClient call to
  410.   get a client handle before using other services.  Most Card Services
  411.   functions will take this client handle as an argument.  Before
  412.   unloading, drivers should also unregister with DeregisterClient.
  413.  
  414.   33..11..11..  RReeggiisstteerrCClliieenntt
  415.  
  416.        int CardServices(RegisterClient, client_handle_t *client, client_reg_t *reg);
  417.  
  418.   The client_reg_t data structure is given by:
  419.  
  420.        typedef struct client_reg_t {
  421.                dev_info_t              *dev_info;
  422.                u_int                   Attributes;
  423.                u_int                   EventMask;
  424.                int                     (*event_handler)(event_t event, int priority,
  425.                                                         event_callback_args_t *args);
  426.                event_callback_args_t   event_callback_args;
  427.                u_int                   Version;
  428.        } client_reg_t;
  429.  
  430.   RegisterClient establishes a link between a client driver and Card
  431.   Services, and connects the client with an appropriate socket.  The
  432.   dev_info parameter is used by Card Services to match the client with a
  433.   socket and function; this correspondence is normally established by
  434.   Driver Services via a call to BindDevice.  If successful, a client
  435.   handle will be returned in client.
  436.  
  437.   The following flags can be specified in Attributes:
  438.  
  439.      INFO_MASTER_CLIENT
  440.         For use only by the Driver Services client.  Among other things,
  441.         specifies that this client should not be automatically unbound
  442.         when a card is ejected from this socket.
  443.  
  444.      INFO_IO_CLIENT
  445.         Specifies that this client is an IO card driver.
  446.  
  447.      INFO_MTD_CLIENT
  448.         Specifies that this client is a Memory Technology Driver.
  449.  
  450.      INFO_MEM_CLIENT
  451.         Specifies that this client is a memory card driver.
  452.  
  453.      INFO_CARD_SHARE
  454.         Included for compatibility, has no effect.
  455.  
  456.      INFO_CARD_EXCL
  457.         Included for compatibility, has no effect.
  458.  
  459.   EventMask specifies what events this client should be notified of.
  460.   The event_handler entry point will be called by Card Services when an
  461.   event in EventMask is processed.  The event_handler_args structure is
  462.   a template for the structure that will be passed to the event handler.
  463.   The Version parameter identifies the Card Services version level that
  464.   this driver expects; it is currently ignored.
  465.  
  466.   A driver should be prepared to handle Card Services events before
  467.   calling RegisterClient.  This call will always generate a
  468.   CS_REGISTRATION_COMPLETE event, and may also generate an artificial
  469.   CS_CARD_INSERTION event if the socket is currently occupied.
  470.  
  471.   Return codes:
  472.  
  473.      CS_OUT_OF_RESOURCE
  474.         An appropriate socket could not be found for this driver.
  475.  
  476.   33..11..22..  DDeerreeggiisstteerrCClliieenntt
  477.  
  478.        int CardServices(DeregisterClient, client_handle_t client);
  479.  
  480.   DeregisterClient severs the connection between a client and Card
  481.   Services.  It should be called after the client has freed any
  482.   resources it has allocated.  Once a connection is broken, it cannot be
  483.   reestablished until after another call to BindDevice.
  484.  
  485.   Return codes:
  486.  
  487.      CS_BAD_HANDLE
  488.         The client handle is invalid.
  489.  
  490.      CS_IN_USE
  491.         The client still has allocated resources, such as IO port
  492.         windows or an interrupt, or the socket configuration is locked.
  493.  
  494.   33..11..33..  SSeettEEvveennttMMaasskk
  495.  
  496.        int CardServices(SetEventMask, client_handle_t client, eventmask_t *mask);
  497.  
  498.   The eventmask_t structure is given by:
  499.  
  500.        typedef struct eventmask_t {
  501.                u_int           Attributes;
  502.                u_int           EventMask;
  503.        } eventmask_t;
  504.  
  505.   SetEventMask updates the mask that determines which events this client
  506.   will be notified of.
  507.  
  508.   Return codes:
  509.  
  510.      CS_BAD_HANDLE
  511.         The client handle is invalid.
  512.  
  513.   33..11..44..  BBiinnddDDeevviiccee
  514.  
  515.        int CardServices(BindDevice, bind_req_t *req);
  516.  
  517.   The bind_req structure is given by:
  518.  
  519.        typedef struct bind_req_t {
  520.                socket_t        Socket;
  521.                u_char          Function;
  522.                dev_info_t      *dev_info;
  523.        } bind_req_t;
  524.  
  525.   BindDevice associates a device driver with a particular socket.  It is
  526.   normally called by Driver Services after a newly inserted card has
  527.   been identified.  Once a driver has been bound to a socket, it will be
  528.   eligible to register as a client of that socket.  Note that this call
  529.   does not take a client handle as an argument.  This is the only Card
  530.   Services call that takes a socket number as an argument.
  531.  
  532.   The Function field specifies which function(s) of a multifunction card
  533.   are to be bound to this driver.  Function numbers correspond to
  534.   entries in the card's CISTPL_LONGLINK_MFC tuple.  If Function is set
  535.   to BIND_FN_ALL, the driver will be bound to all card functions.  A
  536.   driver will only be able to access CIS tuples corresponding to
  537.   functions for which it is bound.
  538.  
  539.   Return codes:
  540.  
  541.      CS_BAD_SOCKET
  542.         The specified socket number is invalid.
  543.  
  544.   33..22..  SSoocckkeett ssttaattee ccoonnttrrooll
  545.  
  546.   These functions are more or less concerned with getting and setting
  547.   the current operating state of a socket.  GetStatus returns the
  548.   current socket state.  ResetCard is used to send a hard reset signal
  549.   to a socket.  SuspendCard and ResumeCard can be used to power down and
  550.   power up a socket without releasing the drivers currently bound to
  551.   that socket.  EjectCard and InsertCard essentially mimic real card
  552.   ejection and insertion events.
  553.  
  554.   33..22..11..  GGeettSSttaattuuss
  555.  
  556.        int CardServices(GetStatus, client_handle_t client, cs_status_t *status);
  557.  
  558.   The cs_status_t data structure is given by:
  559.  
  560.        typedef struct cs_status_t {
  561.                u_char          Function;
  562.                u_int           CardState;
  563.                u_int           SocketState;
  564.        } cs_status_t;
  565.  
  566.   GetStatus returns the current status of a client's socket.  For cards
  567.   that are configured in IO mode, GetStatus uses the Pin Replacement
  568.   Register and Extended Status Register to determine the card status.
  569.   For normal clients, the Function field is ignored, but for clients
  570.   bound with BIND_FN_ALL, this field specifies the function whose
  571.   configuration registers should be used to determine the socket state,
  572.   if the socket is currently configured.  The following flags are
  573.   defined in CardState:
  574.  
  575.      CS_EVENT_CARD_DETECT
  576.         Specifies that the socket is occupied.
  577.  
  578.      CS_EVENT_CB_DETECT
  579.         Specifies that the socket is occupied by a CardBus device.
  580.  
  581.      CS_EVENT_WRITE_PROTECT
  582.         Specifies that the card is currently write protected.
  583.  
  584.      CS_EVENT_BATTERY_LOW
  585.         Specifies that the card battery is low.
  586.  
  587.      CS_EVENT_BATTERY_DEAD
  588.         Specifies that the card battery is dead.
  589.  
  590.      CS_EVENT_READY_CHANGE
  591.         Specifies that the card is ready.
  592.  
  593.      CS_EVENT_PM_SUSPEND
  594.         Specifies that the socket is suspended.
  595.  
  596.      CS_EVENT_REQUEST_ATTENTION
  597.         Specifies that the request attention bit in the extended status
  598.         register is set.
  599.  
  600.      CS_EVENT_CARD_INSERTION
  601.         Specifies that a card insertion event is in progress.  An
  602.         insertion event will be sent to the client when socket setup is
  603.         complete.
  604.  
  605.      CS_EVENT_3VCARD
  606.         Indicates that the card supports 3.3V operation.
  607.  
  608.      CS_EVENT_XVCARD
  609.         Indicates that the card supports ``X.X''V operation.  The actual
  610.         voltage is currently undefined in the specification.
  611.  
  612.   SocketState is currently unused, but in theory, it should latch
  613.   changes in the state of the fields in CardState.
  614.  
  615.   Return codes:
  616.  
  617.      CS_BAD_HANDLE
  618.         The client handle is invalid.
  619.  
  620.   33..22..22..  RReesseettCCaarrdd
  621.  
  622.        int CardServices(ResetCard, client_handle_t client);
  623.  
  624.   ResetCard requests that a client's socket be reset.  When this call is
  625.   made, Card Services sends all clients a CS_EVENT_RESET_REQUEST event.
  626.   If any client rejects the request, Card Services sends the initiating
  627.   client a CS_EVENT_RESET_COMPLETE event with event_callback_args.info
  628.   set to the return code of the client that rejected the request.
  629.  
  630.   If all clients agree to the request, Card Services sends a
  631.   CS_EVENT_RESET_PHYSICAL event, then resets the socket.  When the
  632.   socket signals that it is ready, a CS_EVENT_CARD_RESET event is
  633.   generated.  Finally, a CS_EVENT_RESET_COMPLETE event is sent to the
  634.   initiating client, with event_callback_args.info set to zero.
  635.  
  636.   Return codes:
  637.  
  638.      CS_BAD_HANDLE
  639.         The client handle is invalid.
  640.  
  641.      CS_NO_CARD
  642.         The socket assigned to this client is currently vacant.
  643.      CS_IN_USE
  644.         This socket is currently being reset.
  645.  
  646.   33..22..33..  SSuussppeennddCCaarrdd
  647.  
  648.        int CardServices(SuspendCard, client_handle_t client);
  649.  
  650.   Card Services sends all clients CS_EVENT_PM_SUSPEND events, then shuts
  651.   down and turns off power to the socket.
  652.  
  653.   Return codes:
  654.  
  655.      CS_BAD_HANDLE
  656.         The client handle is invalid.
  657.  
  658.      CS_NO_CARD
  659.         The socket assigned to this client is currently vacant.
  660.  
  661.      CS_IN_USE
  662.         This socket is already suspended.
  663.  
  664.   33..22..44..  RReessuummeeCCaarrdd
  665.  
  666.        int CardServices(ResumeCard, client_handle_t client);
  667.  
  668.   After restoring power to the socket, Card Services will notify all
  669.   clients with CS_EVENT_PM_RESUME events.
  670.  
  671.   Return codes:
  672.  
  673.      CS_BAD_HANDLE
  674.         The client handle is invalid.
  675.  
  676.      CS_NO_CARD
  677.         The socket assigned to this client is currently vacant.
  678.  
  679.      CS_IN_USE
  680.         This socket is not currently suspended.
  681.  
  682.   33..22..55..  EEjjeeccttCCaarrdd
  683.  
  684.        int CardServices(EjectCard, client_handle_t client);
  685.  
  686.   Card Services sends eject events to all clients, then shuts down and
  687.   turns off power to the socket.  All clients except for Driver Services
  688.   will be unlinked from the socket.
  689.  
  690.   Return codes:
  691.  
  692.      CS_BAD_HANDLE
  693.         The client handle is invalid.
  694.  
  695.      CS_NO_CARD
  696.         The socket assigned to this client is currently vacant.
  697.  
  698.   33..22..66..  IInnsseerrttCCaarrdd
  699.  
  700.        int CardServices(InsertCard, client_handle_t client);
  701.  
  702.   Card Services sends insertion events to all clients of this socket
  703.   (normally, only Driver Services).
  704.  
  705.   Return codes:
  706.  
  707.      CS_BAD_HANDLE
  708.         The client handle is invalid.
  709.  
  710.      CS_NO_CARD
  711.         The socket assigned to this client is currently vacant.
  712.  
  713.      CS_IN_USE
  714.         The socket has already been configured.
  715.  
  716.   33..33..  IIOO ccaarrdd ccoonnffiigguurraattiioonn ccaallllss
  717.  
  718.   The normal order of events is for a driver to reserve IO ports and an
  719.   interrupt line with calls to RequestIO and RequestIRQ, then to call
  720.   RequestConfiguration to actually configure the socket.  If any of
  721.   these calls fails, a driver should be sure to release any resources it
  722.   successfully reserved.
  723.  
  724.   Multifunction cards can have separate configurations for each card
  725.   function.  However, the configurations do need to be consistent with
  726.   one another.  While each card function has its own set of
  727.   configuration registers, each socket has only a single interrupt line
  728.   and can only map two contiguous ranges of IO ports.
  729.  
  730.   CardBus cards are configured somewhat differently.  The RequestIO and
  731.   RequestConfiguration calls have similar roles, however, Card Services
  732.   takes responsibility for most of the configuration details, and the
  733.   contents of the request structures are ignored.
  734.  
  735.   33..33..11..  RReeqquueessttIIOO
  736.  
  737.        int CardServices(RequestIO, client_handle_t client, io_req_t *req);
  738.  
  739.   The io_req_t data structure is given by:
  740.  
  741.        typedef struct io_req_t {
  742.                ioaddr_t        BasePort1;
  743.                ioaddr_t        NumPorts1;
  744.                u_int           Attributes1;
  745.                ioaddr_t        BasePort2;
  746.                ioaddr_t        NumPorts2;
  747.                u_int           Attributes2;
  748.                u_int           IOAddrLines;
  749.        } io_req_t;
  750.  
  751.   RequestIO reserves IO port windows for a card.  If BasePort1 is non-
  752.   zero, it specifies the IO port address of the window to be reserved;
  753.   if it is zero, Card Services will find an available window and set
  754.   BasePort1 to this address.  If NumPorts2 is non-zero, a second IO port
  755.   window will also be reserved.  IOAddrLines specifies the number of
  756.   address lines that are actually decoded by the card; this is not
  757.   currently used.
  758.  
  759.   With multifunction cards, this call will allocate IO ports for each
  760.   card function in such a way that all a card's ports can be mapped by
  761.   the two low-level IO port windows associated with each physical
  762.   socket.  For example, if the drivers for a hypothetical four-function
  763.   card each attempt to allocate one IO window of 8 ports, Card Services
  764.   will consolidate these into a single contiguous 32-port block.
  765.  
  766.   When this function is invoked by a CardBus client, the IO request
  767.   structure is ignored.  Instead, Card Services examines the card and
  768.   allocates any necessary system resources: this includes IO and memory
  769.   space, as well as an interrupt, if needed.  One call will reserve all
  770.   resources needed for all card functions, not just the function of the
  771.   client making the call.
  772.  
  773.   This call does not actually configure a socket's IO windows: this is
  774.   done by a subsequent call to RequestConfiguration.
  775.  
  776.   The following flags can be specified in Attributes1 and Attributes2:
  777.  
  778.      IO_DATA_PATH_WIDTH
  779.         This field may either be IO_DATA_PATH_WIDTH_16 for 16-bit
  780.         access, or IO_DATA_PATH_WIDTH_8 for 8-bit access, or
  781.         IO_DATA_PATH_WIDTH_AUTO to dynamically size the bus based on the
  782.         access size.
  783.  
  784.   Return codes:
  785.  
  786.      CS_BAD_HANDLE
  787.         The client handle is invalid.
  788.  
  789.      CS_NO_CARD
  790.         The socket assigned to this client is currently vacant.
  791.  
  792.      CS_IN_USE
  793.         This socket's IO windows have already been reserved.
  794.  
  795.      CS_CONFIGURATION_LOCKED
  796.         This socket's configuration has been locked by a call to
  797.         RequestConfiguration.
  798.  
  799.      CS_BAD_ATTRIBUTE
  800.         An unsupported attribute flag was specified.
  801.   33..33..22..  RReelleeaasseeIIOO
  802.  
  803.        int CardServices(ReleaseIO, client_handle_t client, io_req_t *req);
  804.  
  805.   ReleaseIO un-reserves IO port windows allocated by a previous call to
  806.   RequestIO.  The req parameter should be the same one passed to
  807.   RequestIO.  If several card functions are sharing a larger IO port
  808.   window, ports released by one function may not become available for
  809.   other uses until all card functions have released their IO ports.
  810.  
  811.   For a CardBus client, this call releases all system resources
  812.   allocated for this card.
  813.  
  814.   Return codes:
  815.  
  816.      CS_BAD_HANDLE
  817.         The client handle is invalid.
  818.  
  819.      CS_CONFIGURATION_LOCKED
  820.         This socket's configuration has been locked by a call to
  821.         RequestConfiguration.  The configuration should be released
  822.         before calling ReleaseIO.
  823.  
  824.      CS_BAD_ARGS
  825.         The parameters in req do not match the parameters passed to
  826.         RequestIO.
  827.  
  828.   33..33..33..  RReeqquueessttIIRRQQ
  829.  
  830.        int CardServices(RequestIRQ, client_handle_t client, irq_req_t *req);
  831.  
  832.   The irq_req_t structure is given by:
  833.  
  834.        typedef struct irq_req_t {
  835.                u_int           Attributes;
  836.                u_int           AssignedIRQ;
  837.                u_int           IRQInfo1, IRQInfo2;
  838.                void            *(Handler)(int, struct pt_regs *);
  839.                void            *Instance
  840.        } irq_req_t;
  841.  
  842.   RequestIRQ reserves an interrupt line for use by a card.  The IRQInfo1
  843.   and IRQInfo2 fields correspond to the interrupt description bytes in a
  844.   CFTABLE_ENTRY tuple.  If IRQ_INFO2_VALID is set in IRQInfo1, then
  845.   IRQInfo2 is a bit-mapped mask of allowed interrupt values.  Each bit
  846.   corresponds to one interrupt line: bit 0 = irq 0, bit 1 = irq 1, etc.
  847.   So, a mask of 0x1100 would mean that interrupts 12 and 8 could be
  848.   used.  If IRQ_INFO2_VALID is not set, IRQInfo1 is just the desired
  849.   interrupt number.  If the call is successful, the reserved interrupt
  850.   is returned in AssignedIRQ.
  851.   If the IRQ_HANDLER_PRESENT flag is set, then this call also specifies
  852.   an interrupt handler to be installed when the interrupt is enabled.
  853.   When RequestConfiguration is called, the handler given by Handler will
  854.   be installed.  For 2.0 and later kernels, the interrupt handler will
  855.   be installed with the device ``instance'' given in Instance.  For
  856.   pre-2.1.60 kernels, the kernel irq2dev_map table will also be updated.
  857.   With multifunction cards, the interrupt will be allocated in shared
  858.   mode, and the handler(s) have responsibility for determining which
  859.   card function(s) require attention when an interrupt is received.  If
  860.   a client instead bypasses Card Services to install its own interrupt
  861.   service routine, it should allocate the interrupt in shared mode if
  862.   this client could be bound to a multifunction card.
  863.  
  864.   The following flags can be specified in Attributes:
  865.  
  866.      IRQ_FORCED_PULSE
  867.         Specifies that the interrupt should be configured for pulsed
  868.         mode, rather than the default level mode.
  869.  
  870.      IRQ_TYPE_TIME
  871.         Specifies that this interrupt can be time-shared with other Card
  872.         Services drivers.  Only one driver should enable the interrupt
  873.         at any time.
  874.  
  875.      IRQ_FIRST_SHARED
  876.         In conjunction with IRQ_TYPE_TIME, this should be set by the
  877.         first driver requesting a shared interrupt.
  878.  
  879.      IRQ_HANDLER_PRESENT
  880.         Indicates that the Handler field points to an interrupt service
  881.         routine that should be installed.
  882.  
  883.   Return codes:
  884.  
  885.      CS_BAD_HANDLE
  886.         The client handle is invalid.
  887.  
  888.      CS_NO_CARD
  889.         The socket assigned to this client is currently vacant.
  890.  
  891.      CS_IN_USE
  892.         An interrupt has already been reserved for this socket, or the
  893.         requested interrupt is unavailable.
  894.  
  895.      CS_CONFIGURATION_LOCKED
  896.         This card function's configuration has been locked by a call to
  897.         RequestConfiguration.
  898.  
  899.      CS_BAD_ATTRIBUTE
  900.         An unsupported attribute flag was specified.
  901.  
  902.   33..33..44..  RReelleeaasseeIIRRQQ
  903.  
  904.        int CardServices(ReleaseIRQ, client_handle_t client, irq_req_t *req);
  905.  
  906.   ReleaseIRQ un-reserves an interrupt assigned by an earlier call to
  907.   RequestIRQ.  The req structure should be the same structure that was
  908.   passed to RequestIRQ.  If a handler was specified in the RequestIRQ
  909.   call, it will be unregistered at this time.
  910.   Return codes:
  911.  
  912.      CS_BAD_HANDLE
  913.         The client handle is invalid.
  914.  
  915.      CS_CONFIGURATION_LOCKED
  916.         This socket's configuration has been locked by a call to
  917.         RequestConfiguration.  The configuration should be released
  918.         before calling ReleaseIRQ.
  919.  
  920.      CS_BAD_IRQ
  921.         The parameters in req do not match the parameters passed to
  922.         RequestIRQ.
  923.  
  924.   33..33..55..  RReeqquueessttCCoonnffiigguurraattiioonn
  925.  
  926.        int CardServices(RequestConfiguration, client_handle_t client, config_req_t *req);
  927.  
  928.   The config_req_t structure is given by:
  929.  
  930.        typedef struct config_req_t {
  931.                u_int           Attributes;
  932.                u_int           Vcc, Vpp1, Vpp2;
  933.                u_int           IntType;
  934.                u_int           ConfigBase;
  935.                u_char          Status, Pin, Copy, ExtStatus;
  936.                u_char          ConfigIndex;
  937.                u_int           Present;
  938.        } config_req_t;
  939.  
  940.   RequestConfiguration is responsible for actually configuring a socket.
  941.   This includes setting voltages, setting CIS configuration registers,
  942.   setting up IO port windows, and setting up interrupts.
  943.  
  944.   IntType specifies the type of interface to use for this card.  It may
  945.   be INT_MEMORY, INT_MEMORY_AND_IO, or INT_CARDBUS.  Voltages are
  946.   specified in units of 1/10 volt.  Currently, Vpp1 must equal Vpp2.
  947.  
  948.   With multifunction cards, each card function is configured separately.
  949.   Each function has its own set of CIS configuration registers.
  950.   However, all functions must be configured with the same power and
  951.   interface settings.
  952.  
  953.   When invoked by a CardBus client, the request structure is ignored,
  954.   and all card functions will be configured based on data collected in a
  955.   previous RequestIO call.  This includes configuring the CardBus
  956.   bridge, as well as initializing the Command, Base Address, and
  957.   Interrupt Line registers in each card function's configuration space.
  958.  
  959.   The following flags can be specified in Attributes.  DMA and speaker
  960.   control are not supported on all systems.
  961.  
  962.      CONF_ENABLE_IRQ
  963.         Enable the IO interrupt reserved by a previous call to
  964.         RequestIRQ.
  965.      CONF_ENABLE_DMA
  966.         Enable DMA accesses for this socket.
  967.  
  968.      CONF_ENABLE_SPKR
  969.         Enable speaker output from this socket.
  970.  
  971.   The Present parameter is a bit map specifying which CIS configuration
  972.   registers are implemented by this card.  ConfigBase gives the offset
  973.   of the configuration registers in attribute memory.  The following
  974.   registers can be specified:
  975.  
  976.      PRESENT_OPTION
  977.         Specifies that the Configuration Option Register is present.
  978.         The COR register will be set using the ConfigIndex parameter.
  979.  
  980.      PRESENT_STATUS
  981.         Specifies that the Card Configuration and Status Register is
  982.         present.  The CCSR will be initialized with the Status
  983.         parameter.
  984.  
  985.      PRESENT_PIN_REPLACE
  986.         Specifies that the Pin Replacement Register is present.  The PRR
  987.         will be initialized with the Pin parameter.
  988.  
  989.      PRESENT_COPY
  990.         Specifies that the Socket and Copy Register is present.  The SCR
  991.         will be initialized with the Copy parameter.
  992.  
  993.      PRESENT_EXT_STATUS
  994.         Specifies that the Extended Status Register is present.  The ESR
  995.         will be initialized with the ExtStatus parameter.
  996.  
  997.   Return codes:
  998.  
  999.      CS_BAD_HANDLE
  1000.         The client handle is invalid.
  1001.  
  1002.      CS_NO_CARD
  1003.         The socket assigned to this client is currently vacant.
  1004.  
  1005.      CS_OUT_OF_RESOURCE
  1006.         Card Services was unable to allocate a memory window to access
  1007.         the card's configuration registers.
  1008.  
  1009.      CS_CONFIGURATION_LOCKED
  1010.         This card's configuration has already been locked by another
  1011.         call to RequestConfiguration.
  1012.  
  1013.      CS_BAD_VCC
  1014.         The requested Vcc voltage is not supported.
  1015.  
  1016.      CS_BAD_VPP
  1017.         The requested Vpp1/Vpp2 voltage is not supported.
  1018.  
  1019.   33..33..66..  MMooddiiffyyCCoonnffiigguurraattiioonn
  1020.  
  1021.        int CardServices(ModifyConfiguration, client_handle_t client, modconf_t *mod);
  1022.  
  1023.   The modconf_t structure is given by:
  1024.        typedef struct modconf_t {
  1025.                u_int           Attributes;
  1026.                u_int           Vcc, Vpp1, Vpp2;
  1027.        } modconf_t;
  1028.  
  1029.   ModifyConfiguration modifies some attributes of a socket that has been
  1030.   configured by a call to RequestConfiguration.
  1031.  
  1032.   The following flags can be specified in Attributes:
  1033.  
  1034.      CONF_IRQ_CHANGE_VALID
  1035.         Indicates that the CONF_ENABLE_IRQ setting should be updated.
  1036.  
  1037.      CONF_ENABLE_IRQ
  1038.         Specifies that IO interrupts should be enabled for this socket.
  1039.  
  1040.      CONF_VCC_CHANGE_VALID
  1041.         Indicates that Vcc should be updated.
  1042.  
  1043.      CONF_VPP1_CHANGE_VALID
  1044.         Indicates that Vpp1 should be updated.
  1045.  
  1046.      CONF_VPP2_CHANGE_VALID
  1047.         Indicates that Vpp2 should be updated.
  1048.  
  1049.   Currently, Vpp1 and Vpp2 must always have the same value.  So, the two
  1050.   values must always be changed at the same time.
  1051.  
  1052.   Return codes:
  1053.  
  1054.      CS_BAD_HANDLE
  1055.         The client handle is invalid.
  1056.  
  1057.      CS_NO_CARD
  1058.         The socket assigned to this client is currently vacant.
  1059.  
  1060.      CS_CONFIGURATION_LOCKED
  1061.         This actually means that this socket has nnoott been locked.
  1062.  
  1063.      CS_BAD_VCC
  1064.         The requested Vcc voltage is not supported.
  1065.  
  1066.      CS_BAD_VPP
  1067.         The requested Vpp1/Vpp2 voltage is not supported.
  1068.  
  1069.   33..33..77..  RReelleeaasseeCCoonnffiigguurraattiioonn
  1070.  
  1071.        int CardServices(ReleaseConfiguration, client_handle_t client, config_req_t *req);
  1072.  
  1073.   ReleaseConfiguration un-configures a socket previously set up by a
  1074.   call to RequestConfiguration.  The req parameter should be the same
  1075.   one used to configure the socket.
  1076.  
  1077.   Return codes:
  1078.  
  1079.      CS_BAD_HANDLE
  1080.         The window handle is invalid, or the socket is not configured.
  1081.  
  1082.   33..33..88..  GGeettCCoonnffiigguurraattiioonnIInnffoo
  1083.  
  1084.        int CardServices(GetConfigurationInfo, client_handle_t client, config_info_t *config);
  1085.  
  1086.   The config_info_t structure is given by:
  1087.  
  1088.        typedef struct config_info_t {
  1089.                u_char          Function;
  1090.                u_int           Attributes;
  1091.                u_int           Vcc, Vpp1, Vpp2;
  1092.                u_int           IntType;
  1093.                u_int           ConfigBase;
  1094.                u_char          Status, Pin, Copy, Option, ExtStatus;
  1095.                u_int           Present;
  1096.                u_int           AssignedIRQ;
  1097.                u_int           IRQAttributes;
  1098.                ioaddr_t        BasePort1;
  1099.                ioaddr_t        NumPorts1;
  1100.                u_int           Attributes1;
  1101.                ioaddr_t        BasePort2;
  1102.                ioaddr_t        NumPorts2;
  1103.                u_int           Attributes2;
  1104.                u_int           IOAddrLines;
  1105.        } config_info_t;
  1106.  
  1107.   GetConfigurationInfo returns the current socket configuration as it
  1108.   was set up by RequestIO, RequestIRQ, and RequestConfiguration.  It can
  1109.   only be applied to a fully configured socket.  For normal clients
  1110.   bound to a single card function, the Function field is ignored, and
  1111.   data for that client's assigned function is returned.  For clients
  1112.   bound to BIND_FN_ALL, this field specifies which function's
  1113.   configuration data should be returned.
  1114.  
  1115.   Return codes:
  1116.  
  1117.      CS_BAD_HANDLE
  1118.         The window handle is invalid, or the socket is not configured.
  1119.  
  1120.      CS_NO_CARD
  1121.         The socket assigned to this client is currently vacant.
  1122.  
  1123.      CS_CONFIGURATION_LOCKED
  1124.         This actually means that the configuration has nnoott been locked.
  1125.  
  1126.   33..44..  CCaarrdd IInnffoorrmmaattiioonn SSttrruuccttuurree ((CCIISS)) ccaallllss
  1127.  
  1128.   The definition of the Card Information Structure (CIS) is the darkest
  1129.   chapter of the PC Card standard.  All version 2 compliant cards should
  1130.   have a CIS, which describes the card and how it should be configured.
  1131.   The CIS is a linked list of ``tuples'' in the card's attribute memory
  1132.   space.  Each tuple consists of an identification code, a length byte,
  1133.   and a series of data bytes.  The layout of the data bytes for some
  1134.   tuple types is absurdly complicated, in an apparent effort to use
  1135.   every last bit.
  1136.  
  1137.   The ValidateCIS call checks to see if a card has a reasonable CIS.
  1138.   The GetFirstTuple and GetNextTuple calls are used to step through CIS
  1139.   tuple lists.  GetTupleData extracts data bytes from a tuple.  And
  1140.   ParseTuple unpacks most tuple types into more easily used forms.
  1141.   Finally, the ReplaceCIS call allows a client to provide Card Services
  1142.   with a substitute for the CIS found on the card.
  1143.  
  1144.   33..44..11..  GGeettFFiirrssttTTuuppllee,, GGeettNNeexxttTTuuppllee
  1145.  
  1146.        #include "cistpl.h"
  1147.  
  1148.        int CardServices(GetFirstTuple, client_handle_t client, tuple_t *tuple);
  1149.        int CardServices(GetNextTuple, client_handle_t client, tuple_t *tuple);
  1150.  
  1151.   The tuple_t data structure is given by:
  1152.  
  1153.        typedef struct tuple_t {
  1154.                u_int           Attributes;
  1155.                cis_data_t      DesiredTuple;
  1156.                u_int           Flags;
  1157.                cisdata_t       TupleCode;
  1158.                u_int           TupleLink;
  1159.                cisdata_t       TupleOffset;
  1160.                cisdata_t       TupleDataMax;
  1161.                cisdata_t       TupleDataLen;
  1162.                cisdata_t       *TupleData;
  1163.        } tuple_t;
  1164.  
  1165.   GetFirstTuple searches a card's CIS for the first tuple code matching
  1166.   DesiredTuple.  The special code RETURN_FIRST_TUPLE will match the
  1167.   first tuple of any kind.  If successful, TupleCode is set to the code
  1168.   of the first matching tuple found, and TupleLink is the address of
  1169.   this tuple in attribute memory.
  1170.  
  1171.   GetNextTuple is like GetFirstTuple, except that given a tuple_t
  1172.   structure returned by a previous call to GetFirstTuple or
  1173.   GetNextTuple, it will return the next tuple matching DesiredTuple.
  1174.  
  1175.   These functions will automatically traverse any link tuples found in
  1176.   the CIS.  For multifunction cards having a CISTPL_LONGLINK_MFC tuple,
  1177.   these functions will automatically follow just the CIS chain specific
  1178.   to a client driver's assigned function.  If a client was bound to
  1179.   BIND_FN_ALL, then all tuples will be returned.
  1180.  
  1181.   The following flags can be specified in Attributes:
  1182.  
  1183.      TUPLE_RETURN_LINK
  1184.         Indicates that link tuples (CISTPL_LONGLINK_A,
  1185.         CISTPL_LONGLINK_C, CISTPL_LONGLINK_MFC, CISTPL_NOLINK,
  1186.         CISTPL_LINKTARGET) should be returned.  Normally these tuples
  1187.         are processed silently.
  1188.  
  1189.      TUPLE_RETURN_COMMON
  1190.         Indicates that tuples in the ``common'' CIS section of a
  1191.         multifunction CIS should be returned.  In the absence of this
  1192.         flag, normally, Card Services will only return tuples specific
  1193.         to the function bound to the client.
  1194.  
  1195.   Return codes:
  1196.  
  1197.      CS_BAD_HANDLE
  1198.         The client handle is invalid.
  1199.  
  1200.      CS_OUT_OF_RESOURCE
  1201.         Card Services was unable to set up a memory window to map the
  1202.         card's CIS.
  1203.  
  1204.      CS_NO_MORE_ITEMS
  1205.         There were no tuples matching DesiredTuple.
  1206.  
  1207.   33..44..22..  GGeettTTuupplleeDDaattaa
  1208.  
  1209.        #include "cistpl.h"
  1210.  
  1211.        int CardServices(GetTupleData, client_handle_t client, tuple_t *tuple);
  1212.  
  1213.   GetTupleData extracts a series of data bytes from the specified tuple,
  1214.   which must have been returned by a previous call to GetFirstTuple or
  1215.   GetNextTuple.  A maximum of TupleDataMax bytes will be copied into the
  1216.   TupleData buffer, starting at an offset of TupleOffset bytes.  The
  1217.   number of bytes copied is returned in TupleDataLen.
  1218.  
  1219.   Return codes:
  1220.  
  1221.      CS_BAD_HANDLE
  1222.         The client handle is invalid.
  1223.  
  1224.      CS_OUT_OF_RESOURCE
  1225.         Card Services was unable to set up a memory window to map the
  1226.         card's CIS.
  1227.  
  1228.      CS_NO_MORE_ITEMS
  1229.         The tuple does not contain any more data.  TuppleOffset is
  1230.         greater than or equal to the length of the tuple.
  1231.  
  1232.   33..44..33..  PPaarrsseeTTuuppllee
  1233.  
  1234.        #include "cistpl.h"
  1235.  
  1236.        int CardServices(ParseTuple, client_handle_t client, tuple_t *tuple, cisparse_t *parse);
  1237.  
  1238.   The cisparse_t data structure is given by:
  1239.  
  1240.        typedef union cisparse_t {
  1241.                cistpl_device_t         device;
  1242.                cistpl_checksum_t       checksum;
  1243.                cistpl_longlink_t       longlink;
  1244.                cistpl_longlink_mfc_t   longlink_mfc;
  1245.                cistpl_vers_1_t         version_1;
  1246.                cistpl_altstr_t         altstr;
  1247.                cistpl_jedec_t          jedec;
  1248.                cistpl_manfid_t         manfid;
  1249.                cistpl_funcid_t         funcid;
  1250.                cistpl_config_t         config;
  1251.                cistpl_cftable_entry_t  cftable_entry;
  1252.                cistpl_device_geo_t     device_geo;
  1253.                cistpl_vers_2_t         version_2;
  1254.                cistpl_org_t            org;
  1255.        } cisparse_t;
  1256.  
  1257.   ParseTuple interprets tuple data returned by a previous call to
  1258.   GetTupleData.  The structure returned depends on the type of the
  1259.   parsed tuple.  See the cistpl.h file for these structure definitions;
  1260.   some of them are quite complex.
  1261.  
  1262.   Return codes:
  1263.  
  1264.      CS_BAD_TUPLE
  1265.         An error was encounted during parsing of this tuple.  The tuple
  1266.         may be incomplete, or may be formatted incorrectly.
  1267.  
  1268.      CS_UNSUPPORTED_FUNCTION
  1269.         ParseTuple cannot parse the specified tuple type.
  1270.  
  1271.   33..44..44..  VVaalliiddaatteeCCIISS
  1272.  
  1273.        int CardServices(ValidateCIS, client_handle_t client, cisinfo_t *cisinfo);
  1274.  
  1275.   The cisinfo_t structure is given by:
  1276.  
  1277.        typedef struct cisinfo_t {
  1278.                u_int           Chains;
  1279.        } cisinfo_t;
  1280.  
  1281.   ValidateCIS attempts to verify that a card has a reasonable Card
  1282.   Information Structure.  It returns the number of tuples found in
  1283.   Chains.  If the CIS appears to be uninterpretable, Chains will be set
  1284.   to 0.
  1285.  
  1286.   Return codes:
  1287.  
  1288.      CS_BAD_HANDLE
  1289.         The client handle is invalid.
  1290.  
  1291.      CS_OUT_OF_RESOURCE
  1292.         Card Services was unable to set up a memory window to map the
  1293.         card's CIS.
  1294.  
  1295.   33..44..55..  RReeppllaacceeCCIISS
  1296.  
  1297.        int CardServices(ReplaceCIS, client_handle_t client, cisdump_t *cisinfo);
  1298.  
  1299.   The cisdump_t structure is given by:
  1300.  
  1301.        typedef struct cisdump_t {
  1302.                u_int           Length;
  1303.                cisdata_t       Data[CISTPL_MAX_CIS_SIZE];
  1304.        } cisinfo_t;
  1305.  
  1306.   ReplaceCIS allows a client to pass Card Services a replacement for the
  1307.   CIS found on a card.  Its intended application is for cards with
  1308.   incomplete or inaccurate CIS information.  If a correct CIS can be
  1309.   deduced from other information available for the card, this allows
  1310.   that information to be provided to clients in a clean fashion.  The
  1311.   alternative is to pollute client source code with fixes targeted for
  1312.   each card with a CIS error.  The replacement CIS remains in effect
  1313.   until the card is ejected, and all tuple-related services will use the
  1314.   replacement instead of the card's actual CIS.
  1315.  
  1316.   The Length field gives the number of bytes of CIS data in the Data
  1317.   array.  The Data array can be considered to be just the even bytes of
  1318.   a card's attribute memory.  It should contain all required features of
  1319.   a normal CIS, including an initial CISTPL_DEVICE tuple and a final
  1320.   CISTPL_END tuple.  Long links (including CISTPL_LONGLINK_MFC) may be
  1321.   used: all target addresses are interpreted in the replacement CIS
  1322.   space.  In general, a replacement CIS should also contain the same
  1323.   basic identification tuples (CISTPL_MANFID, CISTPL_VERS_1) as the
  1324.   original card.
  1325.  
  1326.   Return codes:
  1327.  
  1328.      CS_BAD_HANDLE
  1329.         The client handle is invalid.
  1330.  
  1331.      CS_OUT_OF_RESOURCE
  1332.         Card Services was unable to allocate memory to hold the
  1333.         replacement CIS.
  1334.  
  1335.   33..55..  MMeemmoorryy wwiinnddooww ccoonnttrrooll
  1336.  
  1337.   Each socket can have up to four active memory windows, mapping
  1338.   portions of card memory into the host system address space.  A PC Card
  1339.   device can address at most 16MB of both common and attribute memory.
  1340.   Windows should typically be sized to a power of two, and be aligned on
  1341.   a boundary that is a multiple of the window size in both the host and
  1342.   card address spaces.
  1343.  
  1344.   A memory window is initialized by a call to RequestWindow.  Some
  1345.   window attributes can be modified using ModifyWindow.  The segment of
  1346.   card memory mapped to the window can be modified using MapMemPage.
  1347.   And windows are released with ReleaseWindow.  Unlike almost all other
  1348.   Card Services subfunctions, the memory window functions normally act
  1349.   on window_handle_t handles, rather than client_handle_t handles.
  1350.  
  1351.   33..55..11..  RReeqquueessttWWiinnddooww
  1352.  
  1353.        int CardServices(RequestWindow, client_handle_t *handle, win_req_t *req);
  1354.  
  1355.   The win_req_t structure is given by:
  1356.  
  1357.        typedef struct win_req_t {
  1358.                u_int           Attributes;
  1359.                u_long          Base;
  1360.                u_int           Size;
  1361.                u_int           AccessSpeed;
  1362.        } win_req_t;
  1363.  
  1364.   RequestWindow maps a window of card memory into system memory.  On
  1365.   entry, the handle parameter should point to a valid client handle.  On
  1366.   return, this will be replaced by a window_handle_t handle that should
  1367.   be used in subsequent calls to ModifyWindow, MapMemPage, and
  1368.   ReleaseWindow.
  1369.  
  1370.   The following flags can be specified in Attributes:
  1371.  
  1372.      WIN_MEMORY_TYPE
  1373.         This field can be either WIN_MEMORY_TYPE_CM for common memory,
  1374.         or WIN_MEMORY_TYPE_AM for attribute memory.
  1375.  
  1376.      WIN_DATA_WIDTH
  1377.         Either WIN_DATA_WIDTH_16 for 16-bit accesses, or
  1378.         WIN_DATA_WIDTH_8 for 8-bit access.
  1379.  
  1380.      WIN_ENABLE
  1381.         If this is set, the window is turned on.
  1382.  
  1383.      WIN_USE_WAIT
  1384.         Specifies that the controller should observe the card's MWAIT
  1385.         signal.
  1386.  
  1387.   Base specifies the base physical address of the window in system
  1388.   memory.  If zero, Card Services will set Base to the first available
  1389.   window address.  Size specifies the window size in bytes.  If zero,
  1390.   Card Services will set Size to the smallest window size supported by
  1391.   the host controller.  AccessSpeed specifies the memory access speed,
  1392.   in nanoseconds.
  1393.  
  1394.   Return codes:
  1395.  
  1396.      CS_BAD_HANDLE
  1397.         The client handle is invalid.
  1398.  
  1399.      CS_NO_CARD
  1400.         The socket assigned to this client is currently vacant.
  1401.  
  1402.      CS_BAD_ATTRIBUTE
  1403.         An unsupported window attribute was requested.
  1404.  
  1405.      CS_OUT_OF_RESOURCE
  1406.         The maximum number of memory windows for this socket are already
  1407.         being used.
  1408.  
  1409.      CS_IN_USE
  1410.         RequestWindow was unable to find a free window of system memory.
  1411.  
  1412.   33..55..22..  MMooddiiffyyWWiinnddooww
  1413.  
  1414.        int CardServices(ModifyWindow, window_handle_t, modwin_t *);
  1415.  
  1416.   The modwin_t structure is given by:
  1417.  
  1418.        typedef struct modwin_t {
  1419.                u_int           Attributes;
  1420.                u_int           AccessSpeed;
  1421.        } modwin_t;
  1422.  
  1423.   ModifyWindow modifies the attributes of a window handle returned by a
  1424.   previous call to RequestWindow.  The following attributes can be
  1425.   changed:
  1426.  
  1427.      WIN_MEMORY_TYPE
  1428.         This field can be either WIN_MEMORY_TYPE_CM for common memory,
  1429.         or WIN_MEMORY_TYPE_AM for attribute memory.
  1430.  
  1431.      WIN_DATA_WIDTH
  1432.         Either WIN_DATA_WIDTH_16 for 16-bit accesses, or
  1433.         WIN_DATA_WIDTH_8 for 8-bit access.
  1434.  
  1435.      WIN_ENABLE
  1436.         If this is set, the window is turned on.
  1437.  
  1438.   AccessSpeed gives the new memory access speed, in nanoseconds.
  1439.  
  1440.   Return codes:
  1441.  
  1442.      CS_BAD_HANDLE
  1443.         The window handle is invalid.
  1444.  
  1445.   33..55..33..  MMaappMMeemmPPaaggee
  1446.  
  1447.   int CardServices(MapMemPage, window_handle_t, memreq_t *);
  1448.  
  1449.   The memreq_t structure is given by:
  1450.  
  1451.        typedef struct memreq_t {
  1452.                u_int           CardOffset;
  1453.                page_t          Page;
  1454.        } memreq_t;
  1455.  
  1456.   MapMemPage sets the address of card memory that is mapped to the base
  1457.   of a memory window to CardOffset.  The window should have been created
  1458.   by a call to RequestWindow.  The Page parameter is not implemented in
  1459.   this version and should be set to 0.
  1460.  
  1461.   Return codes:
  1462.  
  1463.      CS_BAD_HANDLE
  1464.         The window handle is invalid.
  1465.  
  1466.      CS_BAD_PAGE
  1467.         The Page value was non-zero.
  1468.  
  1469.   33..55..44..  RReelleeaasseeWWiinnddooww
  1470.  
  1471.        int CardServices(ReleaseWindow, window_handle_t handle);
  1472.  
  1473.   ReleaseWindow releases a memory window previously allocated with
  1474.   RequestWindow.
  1475.  
  1476.   Return codes:
  1477.  
  1478.      CS_BAD_HANDLE
  1479.         The window handle is invalid.
  1480.  
  1481.   33..66..  BBuullkk MMeemmoorryy SSeerrvviicceess
  1482.  
  1483.   Bulk memory services provide a higher level interface for accessing
  1484.   memory regions than that provided by the memory window services.  A
  1485.   client using bulk memory calls does not need to know anything about
  1486.   the underlying memory organization or access methods.  The device-
  1487.   specific code is packaged into a special Card Services client called a
  1488.   Memory Technology Driver.
  1489.  
  1490.   33..66..11..  RReeggiisstteerrMMTTDD
  1491.  
  1492.   int CardServices(RegisterMTD, client_handle_t handle, mtd_reg_t *reg);
  1493.  
  1494.   The mtd_reg_t data structure is given by:
  1495.  
  1496.        typedef union mtd_reg_t {
  1497.                u_int           Attributes;
  1498.                u_int           Offset;
  1499.                u_long          MediaID;
  1500.        } mtd_reg_t;
  1501.  
  1502.   RegisterMTD informs Card Services that this client MTD will handle
  1503.   requests for a specified memory region.  The Offset field specifies
  1504.   the starting address of the memory region.  The following fields are
  1505.   defined in Attributes:
  1506.  
  1507.      REGION_TYPE
  1508.         Either REGION_TYPE_CM for common memory, or REGION_TYPE_AM for
  1509.         attribute memory.
  1510.  
  1511.   The MediaID field is recorded by Card Services, and will be passed to
  1512.   the MTD as part of any request that references this memory region.
  1513.  
  1514.   Once an MTD is bound to a memory region by a call to RegisterMTD, it
  1515.   will remain bound until the MTD calls DeregisterClient.
  1516.  
  1517.   Return codes:
  1518.  
  1519.      CS_BAD_HANDLE
  1520.         The client handle is invalid.
  1521.  
  1522.      CS_BAD_OFFSET
  1523.         Either the offset does not match a valid memory region for this
  1524.         card, or another MTD has already registered for this region.
  1525.  
  1526.   33..66..22..  GGeettFFiirrssttRReeggiioonn,, GGeettNNeexxttRReeggiioonn
  1527.  
  1528.        int CardServices(GetFirstRegion, client_handle_t handle, region_info_t *region);
  1529.        int CardServices(GetNextRegion, client_handle_t handle, region_info_t *region);
  1530.  
  1531.   The region_info_t data structure is given by:
  1532.  
  1533.   typedef union region_info_t {
  1534.           u_int           Attributes;
  1535.           u_int           CardOffset;
  1536.           u_int           RegionSize;
  1537.           u_int           AccessSpeed;
  1538.           u_int           BlockSize;
  1539.           u_int           PartMultiple;
  1540.           u_char          JedecMfr, JedecInfo;
  1541.           memory_handle_t next;
  1542.   } region_info_t;
  1543.  
  1544.   GetFirstRegion and GetNextRegion summarize the information in a card's
  1545.   CISTPL_DEVICE, CISTPL_JEDEC, and CISTPL_DEVICE_GEO tuples.  CardOffset
  1546.   gives the starting address of a region. RegionSize gives the length of
  1547.   the region in bytes.  AccessSpeed gives the device's cycle time in
  1548.   nanoseconds.  BlockSize gives the erase block size in bytes, and
  1549.   PartMultiple gives the minimum granularity of partitions on this
  1550.   device, in units of BlockSize.  JedecMfr and JedecInfo give the JEDEC
  1551.   identification bytes for this region.
  1552.  
  1553.   The following fields are defined in Attributes:
  1554.  
  1555.      REGION_TYPE
  1556.         Either REGION_TYPE_CM for common memory, or REGION_TYPE_AM for
  1557.         attribute memory.
  1558.  
  1559.   When these calls are made by an MTD client, only regions that have
  1560.   been bound to this client through calls to BindMTD will be returned.
  1561.  
  1562.   Return codes:
  1563.  
  1564.      CS_BAD_HANDLE
  1565.         The client handle is invalid.
  1566.  
  1567.      CS_NO_MORE_ITEMS
  1568.         No more memory regions are defined.
  1569.  
  1570.   33..66..33..  OOppeennMMeemmoorryy
  1571.  
  1572.        int CardServices(OpenMemory, client_handle_t *handle, open_mem_t *req);
  1573.  
  1574.   The open_mem_t structure is given by:
  1575.  
  1576.        typedef struct open_mem_t {
  1577.                u_int           Attributes;
  1578.                u_int           Offset;
  1579.        } open_mem_t;
  1580.  
  1581.   OpenMemory is used to obtain a handle for accessing a memory region
  1582.   via the other bulk memory services.  The Offset field specifies the
  1583.   base address of the region to be accessed.  If successful, the client
  1584.   handle argument is replaced by the new memory handle.
  1585.  
  1586.   The following fields are defined in Attributes:
  1587.  
  1588.      MEMORY_TYPE
  1589.         Either MEMORY_TYPE_CM for common memory, or MEMORY_TYPE_AM for
  1590.         attribute memory.
  1591.  
  1592.      MEMORY_EXCLUSIVE
  1593.         Specifies that this client should have exclusive access to this
  1594.         memory region.
  1595.  
  1596.   Return codes:
  1597.  
  1598.      CS_BAD_HANDLE
  1599.         The window handle is invalid.
  1600.  
  1601.      CS_BAD_OFFSET
  1602.         Either the offset does not specify a valid region, or the region
  1603.         does not have an associated MTD to service bulk memory requests.
  1604.  
  1605.   33..66..44..  CClloosseeMMeemmoorryy
  1606.  
  1607.        int CardServices(CloseMemory, memory_handle_t handle);
  1608.  
  1609.   CloseMemory releases a memory handle returned by a previous call to
  1610.   OpenMemory.  A client should release all memory handles before calling
  1611.   DeregisterClient.
  1612.  
  1613.   Return codes:
  1614.  
  1615.      CS_BAD_HANDLE
  1616.         The memory handle is invalid.
  1617.  
  1618.   33..66..55..  RReeaaddMMeemmoorryy,, WWrriitteeMMeemmoorryy
  1619.  
  1620.        int CardServices(ReadMemory, memory_handle_t handle mem_op_t *req, caddr_t buf);
  1621.        int CardServices(WriteMemory, memory_handle_t handle, mem_op_t *req, caddr_t buf);
  1622.  
  1623.   The mem_io_t structure is given by:
  1624.  
  1625.        typedef struct mem_op_t {
  1626.                u_int           Attributes;
  1627.                u_int           Offset;
  1628.                u_int           Count;
  1629.        } mem_op_t;
  1630.  
  1631.   ReadMemory and WriteMemory read from and write to a card memory area
  1632.   defined by the specified memory handle, returned by a previous call to
  1633.   OpenMemory.  The Offset field gives the offset of the operation from
  1634.   the start of the card memory region.  The Count field gives the number
  1635.   of bytes to be transferred.  The buf field points to a host memory
  1636.   buffer to be the destination for a ReadMemory operation, or the source
  1637.   for a WriteMemory operation.
  1638.  
  1639.   The following fields are defined in Attributes:
  1640.  
  1641.      MEM_OP_BUFFER
  1642.         Either MEM_OP_BUFFER_USER if the host buffer is in a user memory
  1643.         segment, or MEM_OP_BUFFER_KERNEL if the host buffer is in kernel
  1644.         memory.
  1645.  
  1646.      MEM_OP_DISABLE_ERASE
  1647.         Specifies that a card area should not be erased before it is
  1648.         written.
  1649.  
  1650.      MEM_OP_VERIFY
  1651.         Specifies verification of write operations.
  1652.  
  1653.   Return codes:
  1654.  
  1655.      CS_BAD_HANDLE
  1656.         The window handle is invalid.
  1657.  
  1658.      CS_BAD_OFFSET
  1659.         The specified card offset is beyond the end of the memory
  1660.         region.
  1661.  
  1662.      CS_BAD_SIZE
  1663.         The specified transfer size extends past the end of the memory
  1664.         region.
  1665.  
  1666.   33..66..66..  RReeggiisstteerrEErraasseeQQuueeuuee
  1667.  
  1668.        int CardServices(RegisterEraseQueue, client_handle_t *handle, eraseq_hdr_t *header);
  1669.  
  1670.   The eraseq_hdr_t structure is given by:
  1671.  
  1672.        typedef struct erase_queue_header_t {
  1673.                int             QueueEntryCount;
  1674.                eraseq_entry_t  *QueueEntryArray;
  1675.        } eraseq_hdr_t;
  1676.  
  1677.   This call registers a queue of erase requests with Card Services.  An
  1678.   eraseq_handle_t handle will be returned in *handle.  When this client
  1679.   calls CheckEraseQueue, Card Services will scan the queue and begin
  1680.   asynchronous processing of any new requests.
  1681.  
  1682.   The eraseq_entry_t structure is given by:
  1683.  
  1684.   typedef struct eraseq_entry_t {
  1685.           memory_handle_t Handle;
  1686.           u_char          State;
  1687.           u_int           Size;
  1688.           u_int           Offset;
  1689.           void            *Optional;
  1690.   } eraseq_entry_t;
  1691.  
  1692.   In an erase queue entry, the Header field should be a memory handle
  1693.   returned by a previous call to OpenMemory.  The State field indicates
  1694.   the state of the erase request.  The following values are defined:
  1695.  
  1696.      ERASE_QUEUED
  1697.         Set by the client to indicate that this is a new request.
  1698.  
  1699.      ERASE_IDLE
  1700.         Set by the client to indicate that this entry is not active.
  1701.  
  1702.      ERASE_PASSED
  1703.         Set by the MTD to indicate successful completion.
  1704.  
  1705.      ERASE_FAILED
  1706.         Set by the MTD to indicate that the erase failed.
  1707.  
  1708.      ERASE_MEDIA_WRPROT
  1709.         Indicates that the region is write protected.
  1710.  
  1711.      ERASE_NOT_ERASABLE
  1712.         Indicates that this region does not support erase operations.
  1713.  
  1714.      ERASE_BAD_OFFSET
  1715.         Indicates that the erase does not start on an erase block
  1716.         boundary.
  1717.  
  1718.      ERASE_BAD_SIZE
  1719.         Indicates that the requested erase size is not a multiple of the
  1720.         erase block size.
  1721.  
  1722.      ERASE_BAD_SOCKET
  1723.         Set by the MTD to indicate that there is no card present.
  1724.  
  1725.   Additionally, the macro ERASE_IN_PROGRESS() will return a true
  1726.   condition for values of State that indicate an erase is being
  1727.   processed.
  1728.  
  1729.   The Size field gives the size of the erase request in bytes.  The
  1730.   Offset field gives the offset from the start of the region.  The size
  1731.   and offset should be aligned to erase block boundaries.  The Optional
  1732.   field is not used by Card Services and may be used by the client
  1733.   driver.
  1734.  
  1735.   Return codes:
  1736.  
  1737.      CS_BAD_HANDLE
  1738.         The client handle is invalid.
  1739.  
  1740.   33..66..77..  DDeerreeggiisstteerrEErraasseeQQuueeuuee
  1741.  
  1742.   int CardServices(DeregisterEraseQueue, eraseq_handle_t handle);
  1743.  
  1744.   DeregisterEraseQueue frees a queue previously registered by a call to
  1745.   RegisterEraseQueue.  If there are any pending requests in the
  1746.   specified queue, the call will fail.
  1747.  
  1748.   Return codes:
  1749.  
  1750.      CS_BAD_HANDLE
  1751.         The erase queue handle is invalid.
  1752.  
  1753.      CS_BUSY
  1754.         The erase queue has erase requests pending.
  1755.  
  1756.   33..66..88..  CChheecckkEErraasseeQQuueeuuee
  1757.  
  1758.        int CardServices(CheckEraseQueue, eraseq_handle_t handle);
  1759.  
  1760.   This call notifies Card Services that there are new erase requests in
  1761.   a queue previously registered with RegisterEraseQueue.
  1762.  
  1763.   Typically, a client will initially assign each erase queue entry the
  1764.   state value ERASE_IDLE.  When new requests are added to the queue, the
  1765.   client will set their states to ERASE_QUEUED, and call
  1766.   CheckEraseQueue.  When the client is notified of an erase completion
  1767.   event, it will check the state field to determine whether the request
  1768.   was successful.
  1769.  
  1770.   Return codes:
  1771.  
  1772.      CS_BAD_HANDLE
  1773.         The erase queue handle is invalid.
  1774.  
  1775.   33..77..  MMiisscceellllaanneeoouuss ccaallllss
  1776.  
  1777.   33..77..11..  GGeettCCaarrddSSeerrvviicceessIInnffoo
  1778.  
  1779.        int CardServices(GetCardServicesInfo, servinfo_t *info);
  1780.  
  1781.   The servinfo_t structure is given by:
  1782.  
  1783.   typedef struct servinfo_t {
  1784.           char            Signature[2];
  1785.           u_int           Count;
  1786.           u_int           Revision;
  1787.           u_int           CSLevel;
  1788.           char            *VendorString;
  1789.   } servinfo_t;
  1790.  
  1791.   GetCardServicesInfo returns revision information about this version of
  1792.   Card Services.  Signature is set to ``CS''.  Count is set to the
  1793.   number of sockets currently configured.  Revision is set to the
  1794.   revision level of the Card Services package, and CSLevel is set to the
  1795.   level of compliance with the PC Card standard.  These are encoded as
  1796.   BCD numbers.  VendorString is set to point to an RCS identification
  1797.   string.
  1798.  
  1799.   This call always succeeds.
  1800.  
  1801.   33..77..22..  AAcccceessssCCoonnffiigguurraattiioonnRReeggiisstteerr
  1802.  
  1803.        #include "cisreg.h"
  1804.  
  1805.        int CardServices(AccessConfigurationRegister, client_handle_t handle, conf_reg_t *reg);
  1806.  
  1807.   The conf_reg_t structure is given by:
  1808.  
  1809.        typedef struct conf_reg_t {
  1810.                u_char          Function;
  1811.                u_int           Action;
  1812.                off_t           Offset;
  1813.                u_int           Value;
  1814.        } conf_reg_t;
  1815.  
  1816.   For normal clients bound to a specific card function, the Function
  1817.   field is ignored.  For clients bound to BIND_FN_ALL, this field
  1818.   specifies which function's configuration registers should be accessed.
  1819.  
  1820.   The Action parameter can be one of the following:
  1821.  
  1822.      CS_READ
  1823.         Read the specified configuration register and return Value.
  1824.  
  1825.      CS_WRITE
  1826.         Write Value to the specified configuration register.
  1827.  
  1828.   AccessConfigurationRegister either reads or writes the one-byte CIS
  1829.   configuration register at offset Offset from the start of the config
  1830.   register area.  It can only be used for a socket that has been
  1831.   configured with RequestConfiguration.
  1832.  
  1833.   The following values for Offset are defined in cistpl.h:
  1834.  
  1835.      CISREG_COR
  1836.         The Configuration Option Register.
  1837.  
  1838.      CISREG_CCSR
  1839.         The Card Configuration and Status Register.
  1840.  
  1841.      CISREG_PRR
  1842.         The Pin Replacement Register.
  1843.  
  1844.      CISREG_SCR
  1845.         The Socket and Copy Register.
  1846.  
  1847.      CISREG_ESR
  1848.         The Extended Status Register.
  1849.  
  1850.      CISREG_IOBASE0..CISREG_IOBASE3
  1851.         The I/O Base Registers.
  1852.  
  1853.      CISREG_IOSIZE
  1854.         The I/O Size Register.
  1855.  
  1856.   Return codes:
  1857.  
  1858.      CS_BAD_HANDLE
  1859.         The client handle is invalid.
  1860.  
  1861.      CS_BAD_ARGS
  1862.         The specified Action is not supported.
  1863.  
  1864.      CS_CONFIGURATION_LOCKED
  1865.         This actually means that the configuration has nnoott been locked.
  1866.  
  1867.      CS_OUT_OF_RESOURCE
  1868.         Card Services was unable to allocate a memory window to access
  1869.         the card's configuration registers.
  1870.  
  1871.   33..77..33..  AAddjjuussttRReessoouurrcceeIInnffoo
  1872.  
  1873.        int CardServices(AdjustResourceInfo, client_handle_t handle, adjust_t *adj);
  1874.  
  1875.   The adjust_t structure is given by:
  1876.  
  1877.   typedef struct adjust_t {
  1878.           u_int           Action;
  1879.           u_int           Resource;
  1880.           u_int           Attributes;
  1881.           union {
  1882.                   struct memory {
  1883.                           u_long          Base;
  1884.                           u_long          Size;
  1885.                   } memory;
  1886.                   struct io {
  1887.                           ioaddr_t        BasePort;
  1888.                           ioaddr_t        NumPorts;
  1889.                           u_int           IOAddrLines;
  1890.                   } io;
  1891.                   struct irq {
  1892.                           u_int           IRQ;
  1893.                   } irq;
  1894.           } resource;
  1895.   } adjust_t;
  1896.  
  1897.   AdjustResourceInfo is used to tell Card Services what resources may or
  1898.   may not be allocated by PC Card devices.  The normal Linux resource
  1899.   management systems (the *_region calls for IO ports, interrupt
  1900.   allocation) are respected by Card Services, but this call gives the
  1901.   user another level of control.
  1902.  
  1903.   The Action parameter can have the following values:
  1904.  
  1905.      ADD_MANAGED_RESOURCE
  1906.         Place the specified resource under Card Services control, so
  1907.         that it may be allocated by PC Card devices.
  1908.  
  1909.      REMOVE_MANAGED_RESOURCE
  1910.         Remove the specified resource from Card Services control.
  1911.  
  1912.   At initialization time, Card Services assumes that it can use all
  1913.   available interrupts, but IO ports and memory regions must be
  1914.   explicitly enabled with ADD_MANAGED_RESOURCE.
  1915.  
  1916.   The Resource parameter can have the following values:
  1917.  
  1918.      RES_MEMORY_RANGE
  1919.         Specifies a memory range resource, described by
  1920.         adj->resource.memory.
  1921.  
  1922.      RES_IO_RANGE
  1923.         Specifies an IO port resource, described by adj->resource.io.
  1924.  
  1925.      RES_IRQ
  1926.         Specifies an interrupt resource, described by adj->resource.irq.
  1927.  
  1928.   The following flags may be specified in Attributes:
  1929.  
  1930.      RES_RESERVED
  1931.         Indicates that the resource should be reserved for PC Card
  1932.         devices that specifically request it.  The resource will not be
  1933.         allocated for a device that asks Card Services for any available
  1934.         location.  This is not implemented yet.
  1935.  
  1936.   Return codes:
  1937.  
  1938.      CS_UNSUPPORTED_FUNCTION
  1939.         The specified Action or Resource is not supported.
  1940.      CS_BAD_BASE
  1941.         The specified IO address is out of range.
  1942.  
  1943.      CS_BAD_SIZE
  1944.         The specified memory or IO window size is out of range.
  1945.  
  1946.      CS_IN_USE
  1947.         The specified interrupt is currently allocated by a Card
  1948.         Services client.
  1949.  
  1950.   33..77..44..  RReeppoorrttEErrrroorr
  1951.  
  1952.        int CardServices(ReportError, client_handle_t handle, error_info_t *err);
  1953.  
  1954.   The error_info_t structure is given by:
  1955.  
  1956.        typedef struct error_info_t {
  1957.                int             func;
  1958.                int             retcode;
  1959.        } error_info_t;
  1960.  
  1961.   ReportError generates a kernel error message given a Card Services
  1962.   function code and its return code.  If the client handle is valid,
  1963.   then the error will be prefixed with the client driver's name.  For
  1964.   example:
  1965.  
  1966.        error_info_t err = { RequestIO, CS_BAD_HANDLE };
  1967.        CardServices(ReportError, handle, &err);
  1968.  
  1969.   could generate the following message:
  1970.  
  1971.        serial_cs: RequestIO: Bad handle
  1972.  
  1973.   This call always succeeds.
  1974.  
  1975.   44..  CCaarrdd IInnffoorrmmaattiioonn SSttrruuccttuurree DDeeffiinniittiioonnss
  1976.  
  1977.   44..11..  CCIISS TTuuppllee DDeeffiinniittiioonnss
  1978.  
  1979.   The Card Services ParseTuple function interprets raw CIS tuple data
  1980.   from a call to GetTupleData and returns the tuple contents in a form
  1981.   dependant on the tuple type.  This section describes the parsed tuple
  1982.   contents.
  1983.  
  1984.        #include "cistpl.h"
  1985.  
  1986.   44..11..11..  CCIISSTTPPLL__CCHHEECCKKSSUUMM
  1987.  
  1988.   The cistpl_checksum_t structure is given by:
  1989.  
  1990.        typedef struct cistpl_checksum_t {
  1991.                u_short         addr;
  1992.                u_short         len;
  1993.                u_char          sum;
  1994.        } cistpl_checksum_t;
  1995.  
  1996.   44..11..22..  CCIISSTTPPLL__NNOOLLIINNKK CCIISSTTPPLL__LLOONNGGLLIINNKK__AA,, CCIISSTTPPLL__LLOONNGGLLIINNKK__CC,,
  1997.   CCIISSTTPPLL__LLIINNKKTTAARRGGEETT,,
  1998.  
  1999.   The cistpl_longlink_t structure is given by:
  2000.  
  2001.        typedef struct cistpl_longlink_t {
  2002.                u_int           addr;
  2003.        } cistpl_longlink_t;
  2004.  
  2005.   These tuples are pointers to additional chains of CIS tuples, either
  2006.   in attribute or common memory.  Each CIS tuple chain can have at most
  2007.   one long link.  CISTPL_LONGLINK_A tuples point to attribute memory,
  2008.   and CISTPL_LONGLINK_C tuples point to common memory.  The standard CIS
  2009.   chain starting at address 0 in attribute memory has an implied long
  2010.   link to address 0 in common memory.  A CISTPL_NOLINK tuple can be used
  2011.   to cancel this default link.
  2012.  
  2013.   The first tuple of a chain pointed to by a long link must be a
  2014.   CISTPL_LINKTARGET.  The CS tuple handling code will automatically
  2015.   follow long links and verify link targets; these tuples are normally
  2016.   invisible unless the TUPLE_RETURN_LINK attribute is specified in
  2017.   GetNextTuple.
  2018.  
  2019.   44..11..33..  CCIISSTTPPLL__LLOONNGGLLIINNKK__MMFFCC
  2020.  
  2021.   The cistpl_longlink_mfc_t structure is given by:
  2022.  
  2023.   typedef struct cistpl_longlink_mfc_t {
  2024.           int     nfn;
  2025.           struct {
  2026.                   u_char  space;
  2027.                   u_int   addr;
  2028.           } fn[CISTPL_MAX_FUNCTIONS;
  2029.   } cistpl_longlink_mfc_t;
  2030.  
  2031.   This tuple identifies a multifunction card, and specifies long link
  2032.   pointers to CIS chains specific for each function.  The space field is
  2033.   either CISTPL_MFC_ATTR or CISTPL_MFC_COMMON for attribute or common
  2034.   memory space.
  2035.  
  2036.   44..11..44..  CCIISSTTPPLL__DDEEVVIICCEE,, CCIISSTTPPLL__DDEEVVIICCEE__AA
  2037.  
  2038.   The cistpl_device_t structure is given by:
  2039.  
  2040.        typedef struct cistpl_device_t {
  2041.                int             ndev;
  2042.                struct {
  2043.                        u_char          type;
  2044.                        u_char          wp;
  2045.                        u_int           speed;
  2046.                        u_int           size;
  2047.                } dev[CISTPL_MAX_DEVICES];
  2048.        } cistpl_device_t;
  2049.  
  2050.   The CISTPL_DEVICE tuple describes address regions in a card's common
  2051.   memory.  The CISTPL_DEVICE_A tuple describes regions in attribute
  2052.   memory.  The type flag indicates the type of memory device for this
  2053.   region.  The wp flag indicates if this region is write protected.  The
  2054.   speed field is in nanoseconds, and size is in bytes.  Address regions
  2055.   are assumed to be ordered consecutively starting with address 0.  The
  2056.   following device types are defined:
  2057.  
  2058.      CISTPL_DTYPE_NULL
  2059.         Specifies that there is no device, or a ``hole'' in the card
  2060.         address space.
  2061.  
  2062.      CISTPL_DTYPE_ROM
  2063.         Masked ROM
  2064.  
  2065.      CISTPL_DTYPE_OTPROM
  2066.         One-type programmable ROM.
  2067.  
  2068.      CISTPL_DTYPE_EPROM
  2069.         UV erasable PROM.
  2070.  
  2071.      CISTPL_DTYPE_EEPROM
  2072.         Electrically erasable PROM.
  2073.  
  2074.      CISTPL_DTYPE_FLASH
  2075.         Flash EPROM.
  2076.  
  2077.      CISTPL_DTYPE_SRAM
  2078.         Static or non-volatile RAM.
  2079.  
  2080.      CISTPL_DTYPE_DRAM
  2081.         Dynamic or volatile RAM.
  2082.  
  2083.      CISTPL_DTYPE_FUNCSPEC
  2084.         Specifies a function-specific device, such as a memory-mapped IO
  2085.         device or buffer, as opposed to general purpose storage.
  2086.  
  2087.      CISTPL_DTYPE_EXTEND
  2088.         Specifies an extended device type.  This type is reserved for
  2089.         future use.
  2090.  
  2091.   44..11..55..  CCIISSTTPPLL__VVEERRSS__11
  2092.  
  2093.   The cistpl_vers_1_t structure is given by:
  2094.  
  2095.        typedef struct cistpl_vers_1_t {
  2096.                u_char          major;
  2097.                u_char          minor;
  2098.                int             ns;
  2099.                int             ofs[CISTPL_VERS_1_MAX_PROD_STRINGS];
  2100.                char            str[254];
  2101.        } cistpl_vers_1_t;
  2102.  
  2103.   The ns field specifies the number of product information strings in
  2104.   the tuple.  The string data is contained in the str array.  Each
  2105.   string is null terminated, and ofs gives the offset to the start of
  2106.   each string.
  2107.  
  2108.   44..11..66..  CCIISSTTPPLL__AALLTTSSTTRR
  2109.  
  2110.   The cistpl_altstr_t structure is given by:
  2111.  
  2112.        typedef struct cistpl_altstr_t {
  2113.                int             ns;
  2114.                int             ofs[CISTPL_ALTSTR_MAX_STRINGS];
  2115.                char            str[254];
  2116.        } cistpl_altstr_t;
  2117.  
  2118.   The ns field specifies the number of alternate language strings in the
  2119.   tuple.  The string data is contained in the str array.  Each string is
  2120.   null terminated, and ofs gives the offset to the start of each string.
  2121.  
  2122.   44..11..77..  CCIISSTTPPLL__JJEEDDEECC__CC,, CCIISSTTPPLL__JJEEDDEECC__AA
  2123.  
  2124.   The cistpl_jedec_t structure is given by:
  2125.  
  2126.   typedef struct cistpl_jedec_t {
  2127.           int             nid;
  2128.           struct {
  2129.                   u_char  mfr;
  2130.                   u_char  info;
  2131.           } id[CISTPL_MAX_DEVICES];
  2132.   } cistpl_jedec_t;
  2133.  
  2134.   JEDEC identifiers describe the specific device type used to implement
  2135.   a region of card memory.  The nid field specifies the number of JEDEC
  2136.   identifiers in the tuple.  There should be a one-to-one correspondence
  2137.   between JEDEC identifiers and device descriptions in the corresponding
  2138.   CISTPL_DEVICE tuple.
  2139.  
  2140.   44..11..88..  CCIISSTTPPLL__CCOONNFFIIGG,, CCIISSTTPPLL__CCOONNFFIIGG__CCBB
  2141.  
  2142.   The cistpl_config_t structure is given by:
  2143.  
  2144.        typedef struct cistpl_config_t {
  2145.                u_char          last_idx;
  2146.                u_int           base;
  2147.                u_int           rmask[4];
  2148.                u_char          subtuples;
  2149.        } cistpl_config_t;
  2150.  
  2151.   The last_idx field gives the index of the highest numbered
  2152.   configuration table entry.  The base field gives the offset of a
  2153.   card's configuration registers in attribute memory.  The rmask array
  2154.   is a series of bit masks indicating which configuration registers are
  2155.   present.  Bit 0 of rmask[0] is for the COR, bit 1 is for the CCSR, and
  2156.   so on.  The subtuples field gives the number of bytes of subtuples
  2157.   following the normal tuple contents.
  2158.  
  2159.   For CISTPL_CONFIG_CB, rmask is undefined, and base points to the
  2160.   CardBus status registers.
  2161.  
  2162.   44..11..99..  CCIISSTTPPLL__BBAARR
  2163.  
  2164.   The cistpl_bar_t structure is given by:
  2165.  
  2166.        typedef struct cistpl_bar_t {
  2167.                u_char          attr;
  2168.                u_int           size;
  2169.        } cistpl_long_t;
  2170.  
  2171.   A CISTPL_BAR tuple describes the characteristics of an address space
  2172.   region pointed to by a PCI base address register, for CardBus cards.
  2173.  
  2174.   The following bit fields are defined in attr:
  2175.  
  2176.      CISTPL_BAR_SPACE
  2177.         Identifies the base address register, from 1 to 6.  A value of 7
  2178.         describes the card's Extension ROM space.
  2179.  
  2180.      CISTPL_BAR_SPACE_IO
  2181.         If set, this address register maps IO space (as opposed to
  2182.         memory space).
  2183.  
  2184.      CISTPL_BAR_PREFETCH
  2185.         If set, this region can be prefetched.  controller.
  2186.  
  2187.      CISTPL_BAR_CACHEABLE
  2188.         If set, this region is cacheable as well as prefetchable.
  2189.  
  2190.      CISTPL_BAR_1MEG_MAP
  2191.         If set, this region should only be mapped into the first 1MB of
  2192.         the host's physical address space.
  2193.  
  2194.   44..11..1100..  CCIISSTTPPLL__CCFFTTAABBLLEE__EENNTTRRYY
  2195.  
  2196.   The cistpl_cftable_entry_t structure is given by:
  2197.  
  2198.        typedef struct cistpl_cftable_entry_t {
  2199.                u_char          index;
  2200.                u_char          flags;
  2201.                u_char          interface;
  2202.                cistpl_power_t  vcc, vpp1, vpp2;
  2203.                cistpl_timing_t timing;
  2204.                cistpl_io_t     io;
  2205.                cistpl_irq_t    irq;
  2206.                cistpl_mem_t    mem;
  2207.                u_char          subtuples;
  2208.        } cistpl_cftable_entry_t;
  2209.  
  2210.   A CISTPL_CFTABLE_ENTRY structure describes a complete operating mode
  2211.   for a card.  Many sections are optional.  The index field gives the
  2212.   configuration index for this operating mode; writing this value to the
  2213.   card's Configuration Option Register selects this mode.  The following
  2214.   fields are defined in flags:
  2215.  
  2216.      CISTPL_CFTABLE_DEFAULT
  2217.         Specifies that this is the default configuration table entry.
  2218.  
  2219.      CISTPL_CFTABLE_BVDS
  2220.         Specifies that this configuration implements the BVD1 and BVD2
  2221.         signals in the Pin Replacement Register.
  2222.  
  2223.      CISTPL_CFTABLE_WP
  2224.         Specifies that this configuration implements the write protect
  2225.         signal in the Pin Replacement Register.
  2226.  
  2227.      CISTPL_CFTABLE_RDYBSY
  2228.         Specifies that this configuration implements the Ready/Busy
  2229.         signal in the Pin Replacement Register.
  2230.  
  2231.      CISTPL_CFTABLE_MWAIT
  2232.         Specifies that the WAIT signal should be observed during memory
  2233.         access cycles.
  2234.  
  2235.      CISTPL_CFTABLE_AUDIO
  2236.         Specifies that this configuration generates an audio signal that
  2237.         can be routed to the host system speaker.
  2238.  
  2239.      CISTPL_CFTABLE_READONLY
  2240.         Specifies that the card has a memory region that is read-only in
  2241.         this configuration.
  2242.  
  2243.      CISTPL_CFTABLE_PWRDOWN
  2244.         Specifies that this configuration supports a power down mode,
  2245.         via the Card Configuration and Status Register.
  2246.  
  2247.   The cistpl_power_t structure is given by:
  2248.  
  2249.        typedef struct cistpl_power_t {
  2250.                u_char          present;
  2251.                u_char          flags;
  2252.                u_int           param[7];
  2253.        } cistpl_power_t;
  2254.  
  2255.   The present field is bit mapped and indicates which parameters are
  2256.   present for this power signal.  The following indices are defined:
  2257.  
  2258.      CISTPL_POWER_VNOM
  2259.         The nominal supply voltage.
  2260.  
  2261.      CISTPL_POWER_VMIN
  2262.         The minimum supply voltage.
  2263.  
  2264.      CISTPL_POWER_VMAX
  2265.         The maximum supply voltage.
  2266.  
  2267.      CISTPL_POWER_ISTATIC
  2268.         The continuous supply current required.
  2269.  
  2270.      CISTPL_POWER_IAVG
  2271.         The maximum current averaged over one second.
  2272.  
  2273.      CISTPL_POWER_IPEAK
  2274.         The maximum current averaged over 10 ms.
  2275.  
  2276.      CISTPL_POWER_IDOWN
  2277.         The current required in power down mode.
  2278.  
  2279.   Voltages are given in units of 10 microvolts.  Currents are given in
  2280.   units of 100 nanoamperes.
  2281.  
  2282.   The cistpl_timing_t structure is given by:
  2283.  
  2284.        typedef cistpl_timing_t {
  2285.                u_int           wait, waitscale;
  2286.                u_int           ready, rdyscale;
  2287.                u_int           reserved, rsvscale;
  2288.        } cistpl_timing_t;
  2289.  
  2290.   Each time consists of a base time in nanoseconds, and a scale
  2291.   multiplier.  Unspecified times have values of 0.
  2292.  
  2293.   The cistpl_io_t structure is given by:
  2294.  
  2295.        typedef struct cistpl_io_t {
  2296.                u_char          flags;
  2297.                int             nwin;
  2298.                struct {
  2299.                        u_int           base;
  2300.                        u_int           len;
  2301.                } win[CISTPL_IO_MAX_WIN;
  2302.        } cistpl_io_t;
  2303.  
  2304.   The number of IO windows is given by nwin.  Each window is described
  2305.   by a base address, base, and a length in bytes, len.  The following
  2306.   bit fields are defined in flags:
  2307.  
  2308.      CISTPL_IO_LINES_MASK
  2309.         The number of IO lines decoded by this card.
  2310.  
  2311.      CISTPL_IO_8BIT
  2312.         Indicates that the card supports split 8-bit accesses to 16-bit
  2313.         IO registers.
  2314.  
  2315.      CISTPL_IO_16BIT
  2316.         Indicates that the card supports full 16-bit accesses to IO
  2317.         registers.
  2318.  
  2319.   The cistpl_irq_t structure is given by:
  2320.  
  2321.        typedef struct cistpl_irq_t {
  2322.                u_int           IRQInfo1;
  2323.                u_int           IRQInfo2;
  2324.        } cistpl_irq_t;
  2325.  
  2326.   The following bit fields are defined in IRQInfo1:
  2327.  
  2328.      IRQ_MASK
  2329.         A specific interrupt number that this card should use.
  2330.  
  2331.      IRQ_NMI_ID, IRQ_IOCK_ID, IRQ_BERR_ID,
  2332.         IRQ_VEND_ID" When IRQ_INFO2_VALID is set, these indicate if a
  2333.         corresponding special interrupt signal may be assigned to this
  2334.         card.  The four flags are for the non-maskable, IO check, bus
  2335.         error, and vendor specific interrupts.
  2336.  
  2337.      IRQ_INFO2_VALID
  2338.         Indicates that IRQInfo2 contains a valid bit mask of allowed
  2339.         interrupt request numbers.
  2340.  
  2341.      IRQ_LEVEL_ID
  2342.         Indicates that the card supports level mode interrupts.
  2343.  
  2344.      IRQ_PULSE_ID
  2345.         Indicates that the card supports pulse mode interrupts.
  2346.  
  2347.      IRQ_SHARE_ID
  2348.         Indicates that the card supports sharing interrupts.
  2349.  
  2350.   If IRQInfo1 is 0, then no interrupt information is available.
  2351.  
  2352.   The cistpl_mem_t structure is given by:
  2353.  
  2354.        typedef struct cistpl_mem_t {
  2355.                u_char          nwin;
  2356.                struct {
  2357.                        u_int           len;
  2358.                        u_int           card_addr;
  2359.                        u_int           host_addr;
  2360.                } win[CISTPL_MEM_MAX_WIN;
  2361.        } cistpl_mem_t;
  2362.  
  2363.   The number of memory windows is given by nwin.  Each window is
  2364.   described by an address in the card memory space, card_addr, an
  2365.   address in the host memory space, host_addr, and a length in bytes,
  2366.   len.  If the host address is 0, the position of the window is
  2367.   arbitrary.
  2368.  
  2369.   44..11..1111..  CCIISSTTPPLL__CCFFTTAABBLLEE__EENNTTRRYY__CCBB
  2370.  
  2371.   The cistpl_cftable_entry_cb_t structure is given by:
  2372.  
  2373.        typedef struct cistpl_cftable_entry_cb_t {
  2374.                u_char          index;
  2375.                u_char          flags;
  2376.                cistpl_power_t  vcc, vpp1, vpp2;
  2377.                u_char          io;
  2378.                cistpl_irq_t    irq;
  2379.                u_char          mem;
  2380.                u_char          subtuples;
  2381.        } cistpl_cftable_entry_cb_t;
  2382.  
  2383.   A CISTPL_CFTABLE_ENTRY_CB structure describes a complete operating
  2384.   mode for a CardBus card.  Many fields are identical to corresponding
  2385.   fields in CISTPL_CFTABLE_ENTRY.
  2386.  
  2387.   The io and mem fields specify which base address registers need to be
  2388.   initialized for this configuration.  Bits 1 through 6 correspond to
  2389.   the six base address registers, and bit 7 indicates the expansion ROM
  2390.   base register.
  2391.  
  2392.   44..11..1122..  CCIISSTTPPLL__MMAANNFFIIDD
  2393.  
  2394.   The cistpl_manfid_t structure is given by:
  2395.  
  2396.   typedef struct cistpl_manfid_t {
  2397.           u_short         manf;
  2398.           u_short         card;
  2399.   } cistpl_manfid_t;
  2400.  
  2401.   The manf field identifies the card manufacturer.  The card field is
  2402.   chosen by the vendor and should identify the card type and model.
  2403.  
  2404.   44..11..1133..  CCIISSTTPPLL__FFUUNNCCIIDD
  2405.  
  2406.   The cistpl_funcid_t structure is given by:
  2407.  
  2408.        typedef struct cistpl_funcid_t {
  2409.                u_char          func;
  2410.                u_char          sysinit;
  2411.        } cistpl_funcid_t;
  2412.  
  2413.   The func field identifies the card function.  The sysinit field
  2414.   contains several bit-mapped flags describing how the card should be
  2415.   configured at boot time.
  2416.  
  2417.   The following functions are defined:
  2418.  
  2419.      CISTPL_FUNCID_MULTI
  2420.         A multi-function card.
  2421.  
  2422.      CISTPL_FUNCID_MEMORY
  2423.         A simple memory device.
  2424.  
  2425.      CISTPL_FUNCID_SERIAL
  2426.         A serial port or modem device.
  2427.  
  2428.      CISTPL_FUNCID_PARALLEL
  2429.         A parallel port device.
  2430.  
  2431.      CISTPL_FUNCID_FIXED
  2432.         A fixed disk device.
  2433.  
  2434.      CISTPL_FUNCID_VIDEO
  2435.         A video interface.
  2436.  
  2437.      CISTPL_FUNCID_NETWORK
  2438.         A network adapter.
  2439.  
  2440.      CISTPL_FUNCID_AIMS
  2441.         An auto-incrementing mass storage device.
  2442.  
  2443.   The following flags are defined in sysinit:
  2444.  
  2445.      CISTPL_SYSINIT_POST
  2446.         Indicates that the system should attempt to configure this card
  2447.         during its power-on initialization.
  2448.  
  2449.      CISTPL_SYSINIT_ROM
  2450.         Indicates that the card contains a system expansion ROM that
  2451.         should be configured at boot time.
  2452.  
  2453.   44..11..1144..  CCIISSTTPPLL__DDEEVVIICCEE__GGEEOO
  2454.  
  2455.   The cistpl_device_geo_t structure is given by:
  2456.  
  2457.        typedef struct cistpl_device_geo_t {
  2458.                int             ngeo;
  2459.                struct {
  2460.                        u_char          buswidth;
  2461.                        u_int           erase_block;
  2462.                        u_int           read_block;
  2463.                        u_int           write_block;
  2464.                        u_int           partition;
  2465.                        u_int           interleave;
  2466.                } geo[CISTPL_MAX_DEVICES];
  2467.        } cistpl_device_geo_t;
  2468.  
  2469.   The erase_block, read_block, and write_block sizes are in units of
  2470.   buswidth bytes times interleave.  The partition size is in units of
  2471.   erase_block.
  2472.  
  2473.   44..11..1155..  CCIISSTTPPLL__VVEERRSS__22
  2474.  
  2475.   The cistpl_vers_2_t structure is given by:
  2476.  
  2477.        typedef struct cistpl_vers_2_t {
  2478.                u_char          vers;
  2479.                u_char          comply;
  2480.                u_short         dindex;
  2481.                u_char          vspec8, vspec9;
  2482.                u_char          nhdr;
  2483.                int             vendor, info;
  2484.                char            str[244];
  2485.        } cistpl_vers_2_t;
  2486.  
  2487.   The vers field should always be 0.  The comply field indicates the
  2488.   degree of standard compliance and should also be 0.  The dindex field
  2489.   reserves the specified number of bytes at the start of common memory.
  2490.   The vspec8 and vspec9 fields may contain vendor-specific information.
  2491.   The nhdr field gives the number of copies of the CIS that are present
  2492.   on this card.  The str array contains two strings: a vendor name, and
  2493.   an informational message describing the card.  The offset of the
  2494.   vendor string is given by vendor, and the offset of the product info
  2495.   string is in info.
  2496.  
  2497.   44..11..1166..  CCIISSTTPPLL__OORRGG
  2498.  
  2499.   The cistpl_org_t structure is given by:
  2500.  
  2501.        typedef struct cistpl_org_t {
  2502.                u_char          data_org;
  2503.                char            desc[30];
  2504.  
  2505.   This tuple describes the data organization of a memory partition.  The
  2506.   following values are defined for data_org:
  2507.  
  2508.      CISTPL_ORG_FS
  2509.         The partition contains a filesystem.
  2510.  
  2511.      CISTPL_ORG_APPSPEC
  2512.         The partition is in an application specific format.
  2513.  
  2514.      CISTPL_ORG_XIP
  2515.         The partition follows the Execute-In-Place specification.
  2516.  
  2517.   The desc field gives a text description of the data organization.
  2518.  
  2519.   44..22..  CCIISS ccoonnffiigguurraattiioonn rreeggiisstteerr ddeeffiinniittiioonnss
  2520.  
  2521.   The PC Card standard defines a few standard configuration registers
  2522.   located in a card's attribute memory space.  A card's CONFIG tuple
  2523.   specifies which of these registers are implemented.  Programs using
  2524.   these definitions should include:
  2525.  
  2526.        #include "cisreg.h"
  2527.  
  2528.   44..22..11..  CCoonnffiigguurraattiioonn OOppttiioonn RReeggiisstteerr
  2529.  
  2530.   This register should be present for virtually all IO cards.  Writing
  2531.   to this register selects a configuration table entry and enables a
  2532.   card's IO functions.
  2533.  
  2534.   The following bit fields are defined:
  2535.  
  2536.      COR_CONFIG_MASK
  2537.         Specifies the configuration table index describing the card's
  2538.         current operating mode.
  2539.  
  2540.      COR_LEVEL_REQ
  2541.         Specifies that the card should generate level mode (edge-
  2542.         triggered) interrupts, the default.
  2543.  
  2544.      COR_SOFT_RESET
  2545.         Setting this bit performs a ``soft'' reset operation.  Drivers
  2546.         should use the ResetCard call to reset a card, rather than
  2547.         writing directly to this register.
  2548.  
  2549.   44..22..22..  CCaarrdd CCoonnffiigguurraattiioonn aanndd SSttaattuuss RReeggiisstteerr
  2550.  
  2551.   The following bit fields are defined:
  2552.  
  2553.      CCSR_INTR_ACK
  2554.         If this bit is set, then the CCSR_INTR_PENDING bit will remain
  2555.         set until it is explicitly cleared.
  2556.  
  2557.      CCSR_INTR_PENDING
  2558.         Signals that the card is currently asserting an interrupt
  2559.         request.  This signal may be helpful for supporting interrupt
  2560.         sharing.
  2561.  
  2562.      CCSR_POWER_DOWN
  2563.         Setting this bit signals that the card should enter a power down
  2564.         state.
  2565.  
  2566.      CCSR_AUDIO_ENA
  2567.         Specifies that the card's audio output should be enabled.
  2568.  
  2569.      CCSR_IOIS8
  2570.         This is used by the host to indicate that it can only perform
  2571.         8-bit IO operations and that 16-bit accesses will be carried out
  2572.         as two 8-bit accesses.
  2573.  
  2574.      CCSR_SIGCHG_ENA
  2575.         This indicates to the card that it should use the SIGCHG signal
  2576.         to indicate changes in the WP, READY, BVD1, and BVD2 signals.
  2577.  
  2578.      CCSR_CHANGED
  2579.         This bit signals to the host that one of the signals in the Pin
  2580.         Replacement Register has changed state.
  2581.  
  2582.   44..22..33..  PPiinn RReeppllaacceemmeenntt RReeggiisstteerr
  2583.  
  2584.   Signals in this register replace signals that are not available when a
  2585.   socket is operating in memory and IO mode.  An IO card will normally
  2586.   assert the SIGCHG signal to indicate that one of these signals has
  2587.   changed state, then a driver can poll this register to find out
  2588.   specifically what happened.
  2589.  
  2590.   The following bit fields are defined:
  2591.  
  2592.      PRR_WP_STATUS
  2593.         The current state of the write protect signal.
  2594.  
  2595.      PRR_READY_STATUS
  2596.         The current state of the ready signal.
  2597.  
  2598.      PRR_BVD2_STATUS
  2599.         The current state of the battery warn signal.
  2600.  
  2601.      PRR_BVD1_STATUS
  2602.         The current state of the battery dead signal.
  2603.  
  2604.      PRR_WP_EVENT
  2605.         Indicates that the write protect signal has changed state since
  2606.         the PRR register was last read.
  2607.  
  2608.      PRR_READY_EVENT
  2609.         Indicates that the ready signal has changed state since the PRR
  2610.         register was last read.
  2611.      PRR_BVD2_EVENT
  2612.         Indicates that the battery warn signal has changed state since
  2613.         the PRR register was last read.
  2614.  
  2615.      PRR_BVD1_EVENT
  2616.         Indicates that the battery dead signal has changed state since
  2617.         the PRR register was last read.
  2618.  
  2619.   This register can also be written.  In this case, the STATUS bits act
  2620.   as a mask; if a STATUS bit is set, the corresponding EVENT bit is
  2621.   updated by the write.
  2622.  
  2623.   44..22..44..  SSoocckkeett aanndd CCooppyy RReeggiisstteerr
  2624.  
  2625.   This register is used when several identical cards may be set up to
  2626.   share the same range of IO ports, to emulate an ISA bus card that
  2627.   would control several devices.  For example, an ISA hard drive
  2628.   controller might control several drives, selectable by writing a drive
  2629.   number to an IO port.  For several card drives to emulate this
  2630.   controller interface, each needs to ``know'' which drive it is, so
  2631.   that it can identify which IO operations are intended for it.
  2632.  
  2633.   The following bit fields are defined:
  2634.  
  2635.      SCR_SOCKET_NUM
  2636.         This should indicate the socket number in which the card is
  2637.         located.
  2638.  
  2639.      SCR_COPY_NUM
  2640.         If several identical cards are installed in a system, this field
  2641.         should be set to a unique number identifying which of the
  2642.         identical cards this is.
  2643.  
  2644.   44..22..55..  EExxtteennddeedd SSttaattuuss RReeggiisstteerr
  2645.  
  2646.   The following bit fields are defined:
  2647.  
  2648.      ESR_REQ_ATTN_ENA
  2649.         When set, the CCSR_CHANGED bit will be set when the ESR_REQ_ATTN
  2650.         bit is set, possibly generating a status change interrupt.
  2651.  
  2652.      ESR_REQ_ATTN
  2653.         Signals a card event, such as an incoming call for a modem.
  2654.  
  2655.   44..22..66..  IIOO BBaassee aanndd SSiizzee RReeggiisstteerrss
  2656.  
  2657.   For multifunction cards, these registers are used to tell the card how
  2658.   the host IO windows have been configured for each card function.
  2659.   There are four IO Base registers, from CISREG_IOBASE_0 to
  2660.   CISREG_IOBASE_3, for the low-order through high-order bytes of an IO
  2661.   address up to 32 bits long.  The CISREG_IOSIZE register is supposed to
  2662.   be written as the number of IO ports allocated, minus one.  For MFC-
  2663.   compliant cards, Card Services will automatically set all of these
  2664.   registers when RequestConfiguration is called.
  2665.  
  2666.   55..  CCaarrdd SSeerrvviicceess EEvveenntt HHaannddlliinngg
  2667.  
  2668.   Card Services events have several sources:
  2669.  
  2670.   +o  Card status changes reported by the low-level socket drivers.
  2671.  
  2672.   +o  Artificial events generated by Card Services itself.
  2673.  
  2674.   +o  Advanced Power Management (APM) events.
  2675.  
  2676.   +o  Events generated by other Card Services clients.
  2677.  
  2678.   Socket driver events may be either interrupt-driven or polled.
  2679.  
  2680.   55..11..  EEvveenntt hhaannddlleerr ooppeerraattiioonnss
  2681.  
  2682.   When Card Services recognizes that an event has occurred, it checks
  2683.   the event mask of each client to determine which clients should
  2684.   receive an event notification.  When a client registers with Card
  2685.   Services, it specifies  an event handler callback function.  This
  2686.   handler should have the form:
  2687.  
  2688.        int (*event_handler)(event_t event, int priority, event_callback_args_t *args);
  2689.  
  2690.   The priority parameter is set to either CS_EVENT_PRI_LOW for ordinary
  2691.   events, or CS_EVENT_PRI_HIGH for events that require an immediate
  2692.   response.  The only high priority event is CS_EVENT_CARD_REMOVAL.  A
  2693.   client event handler should process this event as efficiently as
  2694.   possible so that Card Services can quickly notify other clients.
  2695.  
  2696.   The event_callback_args_t structure is given by:
  2697.  
  2698.        typedef struct event_callback_args_t {
  2699.                client_handle_t         client_handle;
  2700.                void                    *info;
  2701.                void                    *mtdrequest;
  2702.                void                    *buffer;
  2703.                void                    *misc;
  2704.                void                    *client_data;
  2705.        } event_callback_args_t;
  2706.  
  2707.   The client_handle member is set to the handle of the client whose
  2708.   socket was responsible for the event.  This is useful if a driver is
  2709.   bound to several sockets.  The info field is currently only used to
  2710.   return an exit status from a call to ResetCard.  The client_data field
  2711.   may be used by a driver to point to a local data structure associated
  2712.   with this device.  The remaining fields are currently unused.
  2713.  
  2714.   55..22..  EEvveenntt ddeessccrriippttiioonnss
  2715.  
  2716.      CS_EVENT_CARD_INSERTION
  2717.         This event signals that a card has been inserted.  If a driver
  2718.         is bound to an already occupied socket, Card Services will send
  2719.         the driver an artificial insertion event.
  2720.  
  2721.      CS_EVENT_CARD_REMOVAL
  2722.         This event signals that a card has been removed.  This event
  2723.         should be handled with minimum delay so that Card Services can
  2724.         notify all clients as quickly as possible.
  2725.  
  2726.      CS_EVENT_BATTERY_LOW
  2727.         This event signals a change of state of the ``battery low''
  2728.         signal.
  2729.  
  2730.      CS_EVENT_BATTERY_DEAD
  2731.         This event signals a change of state of the ``battery dead''
  2732.         signal.
  2733.  
  2734.      CS_EVENT_READY_CHANGE
  2735.         This event signals a change of state of the ``ready'' signal.
  2736.  
  2737.      CS_EVENT_WRITE_PROTECT
  2738.         This event signals a change of state of the ``write protect''
  2739.         signal.
  2740.  
  2741.      CS_EVENT_REGISTRATION_COMPLETE
  2742.         This event is sent to a driver after a successful call to
  2743.         RegisterClient.
  2744.  
  2745.      CS_EVENT_RESET_REQUEST
  2746.         This event is sent when a client calls ResetCard.  An event
  2747.         handler can veto the reset operation by returning failure.
  2748.  
  2749.      CS_EVENT_RESET_PHYSICAL
  2750.         This is sent to all clients just before a reset signal is sent
  2751.         to a card.
  2752.  
  2753.      CS_EVENT_CARD_RESET
  2754.         This event signals that a reset operation is finished.  The
  2755.         success or failure of the reset should be determined using
  2756.         GetStatus.
  2757.  
  2758.      CS_EVENT_RESET_COMPLETE
  2759.         This event is sent to a client that has called ResetCard to
  2760.         signal the end of reset processing.
  2761.  
  2762.      CS_EVENT_PM_SUSPEND
  2763.         This event signals that Card Services has received either a user
  2764.         initiated or APM suspend request.  An event handler can veto the
  2765.         suspend by returning failure.
  2766.  
  2767.      CS_EVENT_PM_RESUME
  2768.         This signals that the system is back on line after a
  2769.         suspend/resume cycle.
  2770.  
  2771.      CS_EVENT_MTD_REQUEST
  2772.         This is used to initiate an MTD memory operation.  A description
  2773.         of the request is passed in the mtdrequest field of the callback
  2774.         arguments.  A host buffer address may be passed in buffer.
  2775.  
  2776.      CS_EVENT_ERASE_COMPLETE
  2777.         This is used to signal a client that a queued erase operation
  2778.         has completed.  A pointer to the erase queue entry is returned
  2779.         in the info field of the callback arguments.
  2780.  
  2781.   55..33..  CClliieenntt ddrriivveerr eevveenntt hhaannddlliinngg rreessppoonnssiibbiilliittiieess
  2782.  
  2783.   A client driver should respond to CS_EVENT_CARD_INSERTION and
  2784.   CS_EVENT_CARD_REMOVAL events by configuring and un-configuring the
  2785.   socket.  Because card removal is a high priority event, the driver
  2786.   should immediately block IO to the socket, perhaps by setting a flag
  2787.   in a device structure, and schedule all other shutdown processing to
  2788.   happen later using a timer interrupt.
  2789.  
  2790.   When a CS_EVENT_PM_RESET_REQUEST event is received, a driver should
  2791.   block IO and release a locked socket configuration.  When a
  2792.   CS_EVENT_CARD_RESET is received, a driver should restore the socket
  2793.   configuration and unblock IO.
  2794.  
  2795.   A CS_EVENT_PM_SUSPEND event should be handled somewhat like a
  2796.   CS_EVENT_PM_RESET_REQUEST event, in that IO should be blocked and the
  2797.   socket configuration should be released.  When a CS_EVENT_PM_RESUME
  2798.   event is received, a driver can expect a card to be ready to be
  2799.   reconfigured, similar to when a CS_EVENT_CARD_RESET event is received.
  2800.  
  2801.   66..  MMeemmoorryy TTeecchhnnoollooggyy DDrriivveerrss
  2802.  
  2803.   A Memory Technology Driver (``MTD'') is used by Card Services to
  2804.   implement bulk memory services for a particular type of memory device.
  2805.   An MTD should register as a normal Card Services client with a call to
  2806.   RegisterClient.  When it receives a card insertion event, it should
  2807.   use GetFirstRegion and GetNextRegion to identify memory regions that
  2808.   it will administer.  Then, it should use RegisterMTD to take control
  2809.   of these regions.  MTD read, write, copy, and erase requests are
  2810.   packaged into CS_EVENT_MTD_REQUEST events by Card Services, and passed
  2811.   to the MTD's event handler for processing.
  2812.  
  2813.   66..11..  MMTTDD rreeqquueesstt hhaannddlliinngg
  2814.  
  2815.   An MTD receives requests from Card Services in the form of
  2816.   CS_EVENT_MTD_REQUEST events.  Card Services passes a description of
  2817.   the request in the mtdrequest field of the event callback arguments.
  2818.   For requests that transfer data to or from the host, the host buffer
  2819.   address is passed in the buffer field.
  2820.  
  2821.   The mtd_request_t structure is given by:
  2822.  
  2823.        typedef struct mtd_request_t {
  2824.                u_int           SrcCardOffset;
  2825.                u_int           DestCardOffset;
  2826.                u_int           TransferLength;
  2827.                u_int           Function;
  2828.                u_long          MediaID;
  2829.                u_int           Status;
  2830.                u_int           Timeout;
  2831.        } mtd_request_t;
  2832.  
  2833.   The Function field is bit mapped and describes the action to be
  2834.   performed by this request:
  2835.  
  2836.      MTD_REQ_ACTION
  2837.         Either MTD_REQ_ERASE, MTD_REQ_READ, MTD_REQ_WRITE, or
  2838.         MTD_REQ_COPY.
  2839.      MTD_REQ_NOERASE
  2840.         For a write command that is sized and aligned on erase block
  2841.         boundaries, this specifies that no erase should be performed.
  2842.  
  2843.      MTD_REQ_VERIFY
  2844.         Specifies that writes should be verified.
  2845.  
  2846.      MTD_REQ_READY
  2847.         Indicates that this request is a retry of a previously request
  2848.         that was delayed until the card asserted READY.
  2849.  
  2850.      MTD_REQ_TIMEOUT
  2851.         Indicates that this request is a retry of a previously request
  2852.         that was delayed by a timeout.
  2853.  
  2854.      MTD_REQ_FIRST
  2855.         Indicates that this request is the first in a series of
  2856.         requests.
  2857.  
  2858.      MTD_REQ_LAST
  2859.         Indicates that this request is the last of a series of requests.
  2860.  
  2861.      MTD_REQ_KERNEL
  2862.         Indicates that the host buffer for a read or write command is
  2863.         located in kernel memory, as opposed to user memory.
  2864.  
  2865.   The MediaID field is the value specified in the RegisterMTD request
  2866.   for this region.  The Status field is used by the MTD when it is
  2867.   unable to satisfy a request because a device is busy.  MTD requests
  2868.   normally run without blocking.  If an MTD request would block, it
  2869.   should return an error code of CS_BUSY, and set Status to one of the
  2870.   have the following values:
  2871.  
  2872.      MTD_WAITREQ
  2873.         Specifies that the request should be retried after another MTD
  2874.         request currently in progress completes.
  2875.  
  2876.      MTD_WAITTIMER
  2877.         Specifies that the request should be continued after the time
  2878.         specified in the timeout field.
  2879.  
  2880.      MTD_WAITRDY
  2881.         Specifies that the request should be continued when the card
  2882.         signals READY, or when the time specified in Timeout elapses,
  2883.         whichever happens first.
  2884.  
  2885.      MTD_WAITPOWER
  2886.         Specifies that the request should be retried after something
  2887.         happens that affects power availability to the socket.
  2888.  
  2889.   For MTD_WAITTIMER and MTD_WAITRDY, the Timeout field will specify the
  2890.   timeout interval in milliseconds.
  2891.  
  2892.   66..22..  MMTTDD hheellppeerr ffuunnccttiioonnss
  2893.  
  2894.   Since an MTD processes requests generated by Card Services, there may
  2895.   be some restrictions on the sorts of Card Services calls that can be
  2896.   safely made from the MTD event handler.  The MTD helper functions
  2897.   provide a limited set of special services that may be needed by an MTD
  2898.   but would be tricky to implement using the normal Card Services calls.
  2899.   In the Linux implementation, most CS calls can be safely made from an
  2900.   MTD event handler, but the MTD helper interface is included for
  2901.   compatibility.
  2902.        #include "cs_types.h"
  2903.        #include "cs.h"
  2904.        #include "bulkmem.h"
  2905.  
  2906.        int MTDHelperEntry(int subfunc, void *arg1, void *arg2);
  2907.  
  2908.   66..22..11..  MMTTDDRReeqquueessttWWiinnddooww,, MMTTDDRReelleeaasseeWWiinnddooww
  2909.  
  2910.        int MTDHelperEntry(MTDRequestWindow, client_handle_t *handle, win_req_t *mod);
  2911.        int MTDHelperEntry(MTDReleaseWindow, window_handle_t handle);
  2912.  
  2913.   These services are identical to the standard Card Services
  2914.   RequestWindow and ReleaseWindow calls.
  2915.  
  2916.   66..22..22..  MMTTDDMMooddiiffyyWWiinnddooww
  2917.  
  2918.        int MTDHelperEntry(MTDModifyWindow, memory_handle_t handle, mtd_mod_req_t *mod);
  2919.  
  2920.   The mtd_mod_req_t structure is give by:
  2921.  
  2922.        typedef struct mtd_mod_req_t {
  2923.                u_int           Attributes;
  2924.                u_int           AccessSpeed;
  2925.                u_int           CardOffset;
  2926.        } mtd_mod_req_t;
  2927.  
  2928.   MTDModifyWindow is essentially equivalent to using the normal
  2929.   ModifyWindow and MapMemPage calls.
  2930.  
  2931.   The following flags can be specified in Attributes:
  2932.  
  2933.      WIN_MEMORY_TYPE
  2934.         Either WIN_MEMORY_TYPE_CM for common memory, or
  2935.         WIN_MEMORY_TYPE_AM for attribute memory.
  2936.  
  2937.      WIN_USE_WAIT
  2938.         Specifies that the controller should observe the card's MWAIT
  2939.         signal.
  2940.  
  2941.   A window configured with MTDModifyWindow will always be enabled, and
  2942.   have a 16 bit data width.
  2943.  
  2944.   Return codes:
  2945.  
  2946.      CS_BAD_HANDLE
  2947.         The memory handle is invalid.
  2948.  
  2949.   66..22..33..  MMTTDDSSeettVVpppp
  2950.  
  2951.        int MTDHelperEntry(MTDSetVpp, client_handle_t client, mtd_vpp_req_t *req);
  2952.  
  2953.        typedef struct mtd_vpp_req_t {
  2954.                u_char          Vpp1, Vpp2;
  2955.        } mtd_vpp_req_t;
  2956.  
  2957.   MTDSetVpp changes the programming voltage for a socket.  Vpp1 and Vpp2
  2958.   should be given in units of 1/10 volt.  Currently, Vpp1 should always
  2959.   equal Vpp2.
  2960.  
  2961.   Return codes:
  2962.  
  2963.      CS_BAD_HANDLE
  2964.         The client handle is invalid.
  2965.  
  2966.      CS_BAD_VPP
  2967.         The specified Vpp is not available, or Vpp1 does not equal Vpp2.
  2968.  
  2969.   66..22..44..  MMTTDDRRDDYYMMaasskk
  2970.  
  2971.        int MTDHelperEntry(MTDRDYMask, client_handle_t client, mtd_rdy_req_t *req);
  2972.  
  2973.        typedef struct mtd_rdy_req_t {
  2974.                u_int           Mask;
  2975.        } mtd_rdy_req_t;
  2976.  
  2977.   MTDRDYMask selects whether or not CS_EVENT_READY_CHANGE events will be
  2978.   enabled.  The client should already have indicated to Card Services
  2979.   that it should receive ready change events, via a call to either
  2980.   RegisterClient or SetEventMask.  Ready change events will be enabled
  2981.   if the CS_EVENT_READY_CHANGE bit is set in the Mask argument.
  2982.  
  2983.   Return codes:
  2984.  
  2985.      CS_BAD_HANDLE
  2986.         The client handle is invalid.
  2987.  
  2988.   77..  DDrriivveerr SSeerrvviicceess iinntteerrffaaccee
  2989.  
  2990.   Driver Services provides a link between Card Services client drivers
  2991.   and user mode utilities like the cardmgr daemon.  It is a sort of Card
  2992.   Services ``super-client''.  Driver Services uses the BindDevice
  2993.   function to link other client drivers with their corresponding cards.
  2994.   Unlike other clients, Driver Services remains permanently bound to all
  2995.   sockets as cards are inserted and removed.
  2996.  
  2997.   77..11..  IInntteerrffaaccee ttoo ootthheerr cclliieenntt ddrriivveerrss
  2998.  
  2999.   Driver Services keeps track of all client drivers that are installed
  3000.   and ready to attach to a socket.  Client drivers need to have entry
  3001.   points for creating and deleting device ``instances'', where one
  3002.   device instance is everything needed to manage one physical card.
  3003.  
  3004.   Each client driver is identified by a unique 16-character tag that has
  3005.   the special type dev_info_t, defined in cs_types.h.  Each device
  3006.   instance is described by a dev_link_t structure.
  3007.  
  3008.   77..11..11..  TThhee ddeevv__lliinnkk__tt ssttrruuccttuurree
  3009.  
  3010.   The dev_node_t and dev_link_t data structures are given by:
  3011.  
  3012.        #include "ds.h"
  3013.  
  3014.        typedef struct dev_node_t {
  3015.                char                    dev_name[DEV_NAME_LEN];
  3016.                u_char                  major, minor;
  3017.                struct dev_node_t       *next;
  3018.        }
  3019.  
  3020.        typedef struct dev_link_t {
  3021.                dev_node_t              *dev;
  3022.                u_int                   state, open;
  3023.                struct wait_queue       *pending
  3024.                struct timer_list       release
  3025.                client_handle_t         handle;
  3026.                io_req_t                io;
  3027.                irq_req_t               irq;
  3028.                config_req_t            conf;
  3029.                window_handle_t         win;
  3030.                void                    *priv;
  3031.                struct dev_link_t       *next;
  3032.        } dev_link_t;
  3033.  
  3034.   The dev field of the dev_link_t structure points to a linked list of
  3035.   dev_node_t structures.  In dev_node_t, the dev_name field should be
  3036.   filled in by the driver with a device file name for accessing this
  3037.   device, if appropriate.  For example, the serial_cs driver uses names
  3038.   like ``ttyS1''.  The major and minor fields give major and minor
  3039.   device numbers for accessing this device.  Driver Services relays
  3040.   these fields to user mode programs via the DS_GET_DEVICE_INFO ioctl.
  3041.  
  3042.   In dev_link_t, the state field should be used to keep track of the
  3043.   current device state.  The following flags are defined:
  3044.  
  3045.      DEV_PRESENT
  3046.         Indicates that the card is present.  This bit should be set and
  3047.         cleared by the driver's event handler in response to card
  3048.         insertion and removal events.
  3049.  
  3050.      DEV_CONFIG
  3051.         Indicates that the card is configured for use.
  3052.  
  3053.      DEV_CONFIG_PENDING
  3054.         Indicates that configuration is in progress.
  3055.  
  3056.      DEV_SUSPEND
  3057.         Indicates that the card is suspended.
  3058.  
  3059.      DEV_BUSY
  3060.         Indicates that an IO operation is in progress.  This bit may be
  3061.         used as an interlock to prevent access conflicts.
  3062.  
  3063.      DEV_STALE_CONFIG
  3064.         For some drivers, when a running card is ejected, the socket
  3065.         should not be unconfigured until any devices corresponding to
  3066.         this card are closed.  This flag indicates that the socket
  3067.         should be unconfigured when the device is closed.
  3068.  
  3069.      DEV_STALE_LINK
  3070.         A driver instance should not be deleted until all its resources
  3071.         are released.  This flag indicates that this driver instance
  3072.         should be freed as soon as the socket is unconfigured.
  3073.  
  3074.   The open field is a usage count for this device.  The device should
  3075.   only be freed when the open count is zero.  The pending field can be
  3076.   used to manage a queue of processes waiting to use the device.
  3077.  
  3078.   The release field is used to schedule device shutdown processing when
  3079.   a card is ejected.  A card removal event needs to be handled at high
  3080.   priority, so a driver's event handler will typically deal with an
  3081.   eject by resetting the DEV_PRESENT bit in the device state, then
  3082.   scheduling the shutdown processing to run at a later time.
  3083.  
  3084.   The handle, io, irq, conf, and win fields comprise all the normal data
  3085.   structures needed to configure an ordinary PC Card IO device
  3086.  
  3087.   The priv field can be used for any sort of private data structure
  3088.   needed to manage the device.  The next field can be used to build
  3089.   linked lists of dev_link_t structures, for drivers that can handle
  3090.   multiple instances.
  3091.  
  3092.   77..11..22..  rreeggiisstteerr__ppccccaarrdd__ddrriivveerr
  3093.  
  3094.        int register_pccard_driver(dev_info_t *dev_info,
  3095.                                   dev_link_t *(*attach)(void),
  3096.                                   void (*detach)(dev_link_t *));
  3097.  
  3098.   register_pccard_driver informs Driver Services that a client driver is
  3099.   present and ready to be bound to sockets.  When Driver Services
  3100.   receives a DS_BIND_REQUEST ioctl that matches this driver's dev_info
  3101.   string, it will call the driver's attach() entry point.  When it gets
  3102.   a DS_UNBIND_REQUEST ioctl, it will call detach().
  3103.  
  3104.   77..11..33..  uunnrreeggiisstteerr__ppccccaarrdd__ddrriivveerr
  3105.  
  3106.        int unregister_pccard_driver(dev_info_t *dev_info);
  3107.  
  3108.   This informs Driver Services that it should no longer bind sockets to
  3109.   the specified client driver.
  3110.  
  3111.   77..22..  TThhee CCaarrddBBuuss cclliieenntt iinntteerrffaaccee
  3112.  
  3113.   The CardBus card interface is designed to be essentially an extension
  3114.   of the PCI bus.  CardBus cards are typically designed using standard
  3115.   PCI chip sets.  For simplicity in the client drivers, and maximum code
  3116.   sharing with regular kernel PCI drivers, we provide a sort of ``super
  3117.   client'' for configuring CardBus cards.  This is implemented in the
  3118.   cb_enabler module.
  3119.  
  3120.   The cb_enabler module is somewhat similar in philosophy to the Driver
  3121.   Services layer for 16-bit cards.  CardBus client drivers register with
  3122.   it, and provide a few entry points for handling device setup and
  3123.   shutdown, as well as power management handling.  The cb_enabler module
  3124.   takes care of configuring the card and fielding Card Services events.
  3125.   So, all CardBus-specific code is in the enabler rather than the PCI
  3126.   driver.
  3127.  
  3128.   It is not mandatory for CardBus clients to use the cb_enabler
  3129.   interface.  If a particular client requires more direct control over
  3130.   its CardBus configuration than is provided through the cb_enabler
  3131.   module, it can register directly with Card Services and perform Card
  3132.   Services calls directly, just like a 16-bit client.
  3133.  
  3134.   The cb_enabler module has two entry points: register_driver and
  3135.   unregister_driver.  At some point, these functions may migrate into
  3136.   the kernel: hence the generic names.
  3137.  
  3138.   77..22..11..  rreeggiisstteerr__ddrriivveerr
  3139.  
  3140.        int register_driver(struct driver_operations *ops);
  3141.  
  3142.   The driver_operations structure is given by:
  3143.  
  3144.        typedef struct driver_operations {
  3145.                char            *name
  3146.                dev_node_t      *(*attach) (dev_locator_t *loc);
  3147.                void            (*suspend) (dev_node_t *dev);
  3148.                void            (*resume) (dev_node_t *dev);
  3149.                void            (*detach) (dev_node_t *dev);
  3150.        } driver_operations;
  3151.  
  3152.   The name field is used by cb_enabler when registering this client with
  3153.   Card Services.  The rest of the structure describes a set of event
  3154.   handlers for this client.
  3155.  
  3156.   The function returns 0 on success, and -1 on failure.
  3157.  
  3158.   77..22..22..  uunnrreeggiisstteerr__ddrriivveerr
  3159.  
  3160.        void unregister_driver(struct driver_operations *ops);
  3161.  
  3162.   The ops parameter should be the same structure pointer passed to a
  3163.   prior successful call to register_driver.  The client should take care
  3164.   to only call this function when no devices are currently being managed
  3165.   by this client.
  3166.  
  3167.   77..22..33..  TThhee ddrriivveerr__ooppeerraattiioonnss eennttrryy ppooiinnttss
  3168.  
  3169.   The attach() entry point is used to configure a single device, given a
  3170.   ``device locator'' structure describing where to find it.
  3171.  
  3172.   The dev_locator_t structure is given by:
  3173.  
  3174.        typedef struct dev_locator_t {
  3175.                enum { LOC_ISA, LOC_PCI } bus;
  3176.                union {
  3177.                        struct {
  3178.                                u_short         io_base_1, io_base_2;
  3179.                                u_long          mem_base;
  3180.                                u_char          irq, dma;
  3181.                        } isa;
  3182.                        struct {
  3183.                                u_char          bus;
  3184.                                u_char          devfn;
  3185.                        } pci;
  3186.                } b;
  3187.        } dev_locator_t;
  3188.  
  3189.   The attach() function should return either NULL or a valid dev_node_t
  3190.   structure describing the new device.  All the other entry points will
  3191.   use this pointer to identify the device to be manipulated.  The
  3192.   cb_enabler module will invoke the attach() and detach() entry points
  3193.   in response to card insertion and removal events.  The suspend() and
  3194.   resume() entry points will be called in response to power management
  3195.   events.
  3196.  
  3197.   There is no way for a driver to refuse a suspend() or detach() event.
  3198.   When a detach() event is received, the driver should block any
  3199.   subsequent IO to the specified device, but may preserve internal data
  3200.   structures until the kernel device is actually closed.
  3201.  
  3202.   77..33..  IInntteerrffaaccee ttoo uusseerr mmooddee uuttiilliittiieess
  3203.  
  3204.   Driver Services creates a pseudo-device for communicating with user
  3205.   mode PC Card utilities.  The major number of the device is chosen
  3206.   dynamically, and PC Card utilities should read /proc/devices to
  3207.   determine it.  Minor device numbers correspond to socket numbers,
  3208.   starting with 0.
  3209.  
  3210.   Only one process is allowed to open a socket for read/write access.
  3211.   Other processes can open the socket in read-only mode.  A read-only
  3212.   connection to Driver Services can perform a subset of ioctl calls.  A
  3213.   read/write connection can issue all ioctl calls, and can also receive
  3214.   Card Services event notifications.
  3215.  
  3216.   77..33..11..  CCaarrdd SSeerrvviicceess eevveenntt nnoottiiffiiccaattiioonnss
  3217.  
  3218.   Driver Services implements read() and select() functions for event
  3219.   notification.  Reading from a PC Card device returns an unsigned long
  3220.   value containing all the events received by Driver Services since the
  3221.   previous read().  If no events have been received, the call will block
  3222.   until the next event.  A select() call can be used to monitor several
  3223.   sockets for new events.
  3224.  
  3225.   The following events are monitored by Driver Services:
  3226.   CS_EVENT_CARD_INSERTION, CS_EVENT_CARD_REMOVAL,
  3227.   CS_EVENT_RESET_PHYSICAL, CS_EVENT_CARD_RESET, and
  3228.   CS_EVENT_RESET_COMPLETE.
  3229.  
  3230.   77..33..22..  IIooccttll ddeessccrriippttiioonnss
  3231.  
  3232.   Most Driver Services ioctl operations directly map to Card Services
  3233.   functions.  An ioctl call has the form:
  3234.  
  3235.        int ioctl(int fd, int cmd, ds_ioctl_arg_t *arg);
  3236.  
  3237.   The ds_ioctl_arg_t structure is given by:
  3238.  
  3239.        typedef union ds_ioctl_arg_t {
  3240.                servinfo_t      servinfo;
  3241.                adjust_t        adjust;
  3242.                config_info_t   config;
  3243.                tuple_t         tuple;
  3244.                tuple_parse_t   tuple_parse;
  3245.                client_req_t    client_req;
  3246.                status_t        status;
  3247.                conf_reg_t      conf_reg;
  3248.                cisinfo_t       cisinfo;
  3249.                region_info_t   region;
  3250.                bind_info_t     bind_info;
  3251.                mtd_info_t      mtd_info;
  3252.                cisdump_t       cisdump;
  3253.        } ds_ioctl_arg_t;
  3254.  
  3255.   The following ioctl commands execute the corresponding Card Services
  3256.   function:
  3257.  
  3258.      DS_GET_CARD_SERVICES_INFO
  3259.         Calls CardServices(GetCardServicesInfo, ..., &arg->servinfo).
  3260.  
  3261.      DS_ADJUST_RESOURCE_INFO
  3262.         Calls CardServices(AdjustResourceInfo, ..., &arg->adjust).
  3263.  
  3264.      DS_GET_CONFIGURATION_INFO
  3265.         Calls CardServices(GetConfigurationInfo, ..., &arg->config).
  3266.  
  3267.      DS_GET_FIRST_TUPLE
  3268.         Calls CardServices(GetFirstTuple, ..., &arg->tuple).
  3269.  
  3270.      DS_GET_NEXT_TUPLE
  3271.         Calls CardServices(GetNextTuple, ..., &arg->tuple).
  3272.  
  3273.      DS_GET_TUPLE_DATA
  3274.         Calls CardServices(GetTupleData, ..., &arg->tuple_parse.tuple).
  3275.         The tuple data is returned in arg->tuple_parse.data.
  3276.  
  3277.      DS_PARSE_TUPLE
  3278.         Calls CardServices(ParseTuple, ..., &arg->tuple_parse.tuple,
  3279.         &arg->tuple_parse.parse).
  3280.  
  3281.      DS_RESET_CARD
  3282.         Calls CardServices(ResetCard, ...).
  3283.  
  3284.      DS_GET_STATUS
  3285.         Calls CardServices(GetStatus, ..., &arg->status).
  3286.  
  3287.      DS_ACCESS_CONFIGURATION_REGISTER
  3288.         Calls CardServices(AccessConfigurationRegister, ...,
  3289.         &arg->conf_reg).
  3290.  
  3291.      DS_VALIDATE_CIS
  3292.         Calls CardServices(ValidateCIS, ..., &arg->cisinfo).
  3293.  
  3294.      DS_SUSPEND_CARD
  3295.         Calls CardServices(SuspendCard, ...).
  3296.  
  3297.      DS_RESUME_CARD
  3298.         Calls CardServices(ResumeCard, ...).
  3299.  
  3300.      DS_EJECT_CARD
  3301.         Calls CardServices(EjectCard, ...).
  3302.  
  3303.      DS_INSERT_CARD
  3304.         Calls CardServices(InsertCard, ...).
  3305.  
  3306.      DS_GET_FIRST_REGION
  3307.         Calls CardServices(GetFirstRegion, ..., &arg->region).
  3308.  
  3309.      DS_GET_NEXT_REGION
  3310.         Calls CardServices(GetNextRegion, ..., &arg->region).
  3311.  
  3312.      DS_REPLACE_CIS
  3313.         Calls CardServices(ReplaceCIS, ..., &arg->cisdump).
  3314.  
  3315.   The following ioctl commands invoke special Driver Services functions.
  3316.   They act on bind_info_t structures:
  3317.  
  3318.   typedef struct bind_info_t {
  3319.           dev_info_t              dev_info;
  3320.           u_char                  function;
  3321.           struct dev_info_t       *instance;
  3322.           char                    name[DEV_NAME_LEN];
  3323.           u_char                  major, minor;
  3324.           void                    *next;
  3325.   } bind_info_t;
  3326.  
  3327.      DS_BIND_REQUEST
  3328.         This call connects a socket to a client driver.  The specified
  3329.         device ID dev_info is looked up in the list of registered
  3330.         drivers.  If this is a multifunction card, the function field
  3331.         identifies which card function is being bound.  If found, the
  3332.         driver is bound to this socket and function using the BindDevice
  3333.         call.  Then, Driver Services calls the client driver's attach()
  3334.         entry point to create a device instance.  The new dev_link_t
  3335.         pointer is returned in instance.
  3336.  
  3337.      DS_GET_DEVICE_INFO
  3338.         This call retrieves the dev_name, major, and minor entries from
  3339.         the dev_link_t structure pointed to by instance.
  3340.  
  3341.      DS_UNBIND_REQUEST
  3342.         This call calls the detach() function for the specified driver
  3343.         and instance, shutting down this device.
  3344.  
  3345.   Finally, the DS_BIND_MTD request takes an argument of type mtd_info_t:
  3346.  
  3347.        typedef struct mtd_info_t {
  3348.                dev_info_t      dev_info;
  3349.                u_int           Attributes;
  3350.                u_int           CardOffset;
  3351.        } mtd_info_t;
  3352.  
  3353.   This call associates an MTD identified by dev_info with a memory
  3354.   region described by Attributes and CardOffset, which have the same
  3355.   meanings as in the Card Services BindMTD call.
  3356.  
  3357.   88..  AAnnaattoommyy ooff aa CCaarrdd SSeerrvviicceess CClliieenntt DDrriivveerr
  3358.  
  3359.   Each release of the Linux Card Services package comes with a well-
  3360.   commented ``dummy'' client driver that should be used as a starting
  3361.   point for writing a new driver.  Look for it in modules/dummy_cs.c.
  3362.   This is not just a piece of sample code: it is written to function as
  3363.   a sort of generic card enabler.  If bound to an IO card, it will read
  3364.   the card's CIS and configure the card appropriately, assuming that the
  3365.   card's CIS is complete and accurate.
  3366.  
  3367.   88..11..  MMoodduullee iinniittiiaalliizzaattiioonn aanndd cclleeaannuupp
  3368.  
  3369.   All loadable modules must supply init_module() and cleanup_module()
  3370.   functions, which are invoked by the module support code when the
  3371.   module is installed and removed.  A client driver's init function
  3372.   should register the driver with Driver Services, via the
  3373.   register_pccard_driver() call.  The cleanup function should use
  3374.   unregister_pccard_driver() to unregister with Driver Services.
  3375.   Depending on the driver, the cleanup function may also need to free
  3376.   any device structures that still exist at shutdown time.
  3377.  
  3378.   88..22..  TThhee **__aattttaacchh(()) aanndd **__ddeettaacchh(()) ffuunnccttiioonnss
  3379.  
  3380.   The *_attach() entry point is responsible for creating an ``instance''
  3381.   of the driver, setting up any data structures needed to manage one
  3382.   card.  The *_attach() function should allocate and initialize a
  3383.   dev_link_t structure, and call RegisterClient to establish a link with
  3384.   Card Services.  It returns a pointer to the new dev_link_t structure,
  3385.   or NULL if the new instance could not be created.
  3386.  
  3387.   The *_detach() entry point deletes a driver instance created by a
  3388.   previous call to *_attach.  It also breaks the link with Card
  3389.   Services, using DeregisterClient.
  3390.  
  3391.   The *_attach() entry point is called by Driver Services when a card
  3392.   has been successfully identified and mapped to a matching driver by a
  3393.   DS_BIND_REQUEST ioctl().  The *_detach() entry point is called in
  3394.   response to a DS_UNBIND_REQUEST ioctl() call.
  3395.  
  3396.   88..33..  TThhee **__ccoonnffiigg(()) aanndd **__rreelleeaassee(()) ffuunnccttiioonnss
  3397.  
  3398.   The *_config() function is called to prepare a card for IO.  Most
  3399.   drivers read some configuration details from the card itsef, but most
  3400.   have at least some built-in knowledge of how the device should be set
  3401.   up.  For example, the serial card driver reads a card's CFTABLE_ENTRY
  3402.   tuples to determine appropriate IO port base addresses and
  3403.   corresponding configuration indices, but the driver ignores the
  3404.   interrupt information in the CIS.  The *_config function will parse
  3405.   relevant parts of a card's CIS, then make calls to RequestIO,
  3406.   RequestIRQ, and/or RequestWindow, then call RequestConfiguration.
  3407.  
  3408.   When a card is successfully configured, the *_config() routine should
  3409.   fill in the dev_name, major, and minor fields in the dev_link_t
  3410.   structure.  These fields will be returned to user programs by Driver
  3411.   Services in response to a DS_GET_DEVICE_INFO ioctl().
  3412.  
  3413.   The *_release() function should release any resource allocated by a
  3414.   previous call to *_config(), and blank out the device's dev_name
  3415.   field.
  3416.  
  3417.   The *_config() and *_release functions are normally called in response
  3418.   to card status change events or from timer interrupts.  Thus, they
  3419.   cannot sleep, and should not call other kernel functions that might
  3420.   block.
  3421.  
  3422.   88..44..  TThhee cclliieenntt eevveenntt hhaannddlleerr
  3423.  
  3424.   The *_event() entry point is called from Card Services to notify a
  3425.   driver of card status change events.
  3426.  
  3427.   88..55..  LLoocckkiinngg aanndd ssyynncchhrroonniizzaattiioonn iissssuueess
  3428.  
  3429.   A configured socket should only be released when all associated
  3430.   devices are closed.  Releasing a socket allows its system resources to
  3431.   be allocated for use by another device.  If the released resources are
  3432.   reallocated while IO to the original device is still in progress, the
  3433.   original driver may interfere with use of the new device.
  3434.  
  3435.   A driver instance should only be freed after its corresponding socket
  3436.   configuration has been released.  Card Services requires that a client
  3437.   explicitly release any allocated resources before a call to
  3438.   DeregisterClient will succeed.
  3439.  
  3440.   All loadable modules have a ``use count'' that is used by the system
  3441.   to determine when it is safe to unload a module.  The convention in
  3442.   client drivers is to increment the use count when a device is opened,
  3443.   and to decrement the count when a device is closed.  So, a driver can
  3444.   be unloaded whenever all associated devices are closed.  in
  3445.   particular, a driver can be unloaded even if it is still bound to a
  3446.   socket, and the module cleanup code needs to be able to appropriately
  3447.   free any such resources that are still allocated.  This should always
  3448.   be safe, because if the driver has a use count of zero, all devices
  3449.   are closed, which means all active sockets can be released, and all
  3450.   device instances can be detached.
  3451.  
  3452.   If a driver's *_release() function is called while a device is still
  3453.   open, it should set the DEV_STALE_CONFIG flag in the device state, to
  3454.   signal that the device should be released when the driver's close()
  3455.   function is called.  If *_detach() is called for a configured device,
  3456.   the DEV_STALE_LINK flag should be set to signal that the instance
  3457.   should be detached when the *_release() function is called.
  3458.  
  3459.   88..66..  UUssiinngg eexxiissttiinngg LLiinnuuxx ddrriivveerrss ttoo aacccceessss PPCC CCaarrdd ddeevviicceess
  3460.  
  3461.   Many of the current client drivers use existing Linux driver code to
  3462.   perform device IO operations.  The Card Services client module handles
  3463.   card configuration and responds to card status change events, but
  3464.   delegates device IO to a compatible driver for a conventional ISA bus
  3465.   card.  In some cases, a conventional driver can be used without
  3466.   modification.  However, to fully support PC Card features like hot
  3467.   swapping and power management, there needs to be some communication
  3468.   between the PC Card client code and the device IO code.
  3469.  
  3470.   Most Linux drivers expect to probe for devices at boot time, and are
  3471.   not designed to handle adding and removing devices.  One side-effect
  3472.   of the move towards driver modularization is that it is usually easier
  3473.   to adapt a modularized driver to handle removable devices.
  3474.  
  3475.   It is important that a device driver be able to recover from having a
  3476.   device disappear at an inappropriate time.  At best, the driver should
  3477.   check for device presence before attempting any IO operation or before
  3478.   handling an IO interrupt.  Loops that check device status should have
  3479.   timeouts so they will eventually exit if a device never responds.
  3480.  
  3481.   The dummy_cs driver may be useful for loading legacy drivers for
  3482.   compatible PC Card devices.  After binding dummy_cs to a card, the
  3483.   legacy driver module may be able to detect and communicate with the
  3484.   device as if it were not a PC Card.  This arrangement will generally
  3485.   not support clean hot swapping or power management functions, however
  3486.   it may be useful as a basis for later developing a more full-featured
  3487.   client driver.
  3488.  
  3489.   99..  TThhee ssoocckkeett ddrriivveerr llaayyeerr
  3490.  
  3491.   In the Linux PCMCIA model, the ``Socket Services'' layer is a private
  3492.   API intended only for the use of Card Services.  The API is based
  3493.   loosely on the PCMCIA Socket Services specification, but implements
  3494.   only the simple subset of its functionality needed for the common
  3495.   laptop host controller types.
  3496.   99..11..  CCaarrdd SSeerrvviicceess eennttrryy ppooiinnttss ffoorr ssoocckkeett ddrriivveerrss
  3497.  
  3498.   Card Services provides special entry points for registering and
  3499.   unregistering socket drivers:
  3500.  
  3501.        typedef int (*ss_entry_t)(u_int sock, u_int cmd, void *arg);
  3502.        extern int register_ss_entry(int nsock, ss_entry_t entry);
  3503.        extern void unregister_ss_entry(ss_entry_t entry);
  3504.  
  3505.   The socket driver invokes register_ss_entry with nsock indicating how
  3506.   many sockets are owned by this driver, and entry pointing to the
  3507.   function that will provide socket services for these sockets.  The
  3508.   unregister_ss_entry routine can be safely invoked whenever Card
  3509.   Services does not have any callback functions registered for sockets
  3510.   owned by this driver.
  3511.  
  3512.   99..22..  SSeerrvviicceess pprroovviiddeedd bbyy tthhee ssoocckkeett ddrriivveerr
  3513.  
  3514.   Socket Services calls have the following form:
  3515.  
  3516.        #include "ss.h"
  3517.  
  3518.        int (*ss_entry)(u_int sock, int service, void *arg);
  3519.  
  3520.   Non-zero return codes indicate that a request failed.
  3521.  
  3522.   99..22..11..  SSSS__IInnqquuiirreeSSoocckkeett
  3523.  
  3524.        int (*ss_entry)(u_int sock, SS_InquireSocket, socket_cap_t *cap);
  3525.  
  3526.   The socket_cap_t data structure is given by:
  3527.  
  3528.        typedef struct socket_cap_t {
  3529.            u_int       features;
  3530.            u_int       irq_mask;
  3531.            u_int       map_size;
  3532.            u_char      pci_irq;
  3533.            u_char      cardbus;
  3534.        } socket_cap_t;
  3535.  
  3536.   The SS_InquireSocket service is used to retrieve socket capabilities.
  3537.   The irq_mask field is a bit mask indicating which interrupts can be
  3538.   configured for IO cards.  The map_size field gives the address
  3539.   granularity of memory windows.  The pci_irq field, if not zero, is the
  3540.   PCI interrupt number assigned to this socket.  It should be consistent
  3541.   with irq_mask.  For CardBus bridges, the cardbus field should be non-
  3542.   zero, and gives the PCI bus number of the CardBus side of the bridge.
  3543.  
  3544.   The following flags may be specified in features:
  3545.  
  3546.      SS_HAS_PAGE_REGS
  3547.         Indicates that this socket supports full 32-bit addressing for
  3548.         16-bit PC Card memory windows.
  3549.  
  3550.   99..22..22..  SSSS__RReeggiisstteerrCCaallllbbaacckk
  3551.  
  3552.        int (*ss_entry)(u_int sock, SS_RegisterCallback, ss_callback_t *call);
  3553.  
  3554.   The ss_callback_t data structure is given by:
  3555.  
  3556.        typedef struct ss_callback_t {
  3557.            void        (*handler)(void *info, u_int events);
  3558.            void        *info;
  3559.        } ss_callback_t;
  3560.  
  3561.   The SS_RegisterCallback service sets up a callback function to be
  3562.   invoked when the socket driver receives card status change events.  To
  3563.   unregister a callback, this function is called with a handler value of
  3564.   NULL.  Only one callback function can be registered per socket.
  3565.  
  3566.   The handler will be called with the value of info that was passed to
  3567.   SS_RegisterCallback for this socket, and with a bit map of events in
  3568.   the events parameter.  The following events are defined:
  3569.  
  3570.      SS_DETECT
  3571.         A card detect change (insertion or removal) has been detected.
  3572.  
  3573.      SS_READY
  3574.         A memory card's ready signal has changed state.
  3575.  
  3576.      SS_BATDEAD
  3577.         A memory card has raised the battery-dead signal.
  3578.  
  3579.      SS_BATWARN
  3580.         A memory card has raised the battery-low signal.
  3581.  
  3582.      SS_STSCHG
  3583.         An IO card has raised the status change signal.
  3584.  
  3585.   99..22..33..  SSSS__GGeettSSttaattuuss
  3586.  
  3587.   int (*ss_entry)(u_int sock, SS_GetStatus, u_int *status);
  3588.  
  3589.   The SS_GetStatus service returns the current status of this socket.
  3590.   The status parameter will be constructed out of the following flags:
  3591.  
  3592.      SS_WRPROT
  3593.         The card is write-protected.
  3594.  
  3595.      SS_BATDEAD
  3596.         A memory card has raised the battery-dead signal.
  3597.  
  3598.      SS_BATWARN
  3599.         A memory card has raised the battery-low signal.
  3600.  
  3601.      SS_READY
  3602.         A memory card has raised its ready signal.
  3603.  
  3604.      SS_DETECT
  3605.         A card detect change (insertion or removal) has been detected.
  3606.  
  3607.      SS_POWERON
  3608.         Power has been applied to the socket.
  3609.  
  3610.      SS_STSCHG
  3611.         An IO card has raised the status change signal.
  3612.  
  3613.      SS_CARDBUS
  3614.         The socket contains a CardBus card (as opposed to a 16-bit PC
  3615.         Card).
  3616.  
  3617.      SS_3VCARD
  3618.         The card must be operated at no more than  3.3V.
  3619.  
  3620.      SS_XVCARD
  3621.         The card must be operated at no more than X.XV (not yet
  3622.         defined).
  3623.  
  3624.   99..22..44..  SSSS__GGeettSSoocckkeett,, SSSS__SSeettSSoocckkeett
  3625.  
  3626.        int (*ss_entry)(u_int sock, SS_GetSocket, socket_state_t *);
  3627.        int (*ss_entry)(u_int sock, SS_SetSocket, socket_state_t *);
  3628.  
  3629.   The socket_state_t data structure is given by:
  3630.  
  3631.        typedef struct socket_state_t {
  3632.            u_int       flags;
  3633.            u_int       csc_mask;
  3634.            u_char      Vcc, Vpp;
  3635.            u_char      io_irq;
  3636.        } socket_state_t;
  3637.  
  3638.   The csc_mask field indicates which event types should generate card
  3639.   status change interrupts.  The following event types can be monitored:
  3640.  
  3641.      SS_DETECT
  3642.         Card detect changes (insertion or removal).
  3643.  
  3644.      SS_READY
  3645.         Memory card ready/busy changes.
  3646.  
  3647.      SS_BATDEAD
  3648.         Memory card battery-dead changes.
  3649.  
  3650.      SS_BATWARN
  3651.         Memory card battery-low changes.
  3652.  
  3653.      SS_STSCHG
  3654.         IO card status changes.
  3655.  
  3656.   The Vcc and Vpp parameters are in units of 0.1 volts.  If non-zero,
  3657.   io_irq specifies an interrupt number to be assigned to the card, in IO
  3658.   mode.  The following fields are defined in flags:
  3659.  
  3660.      SS_PWR_AUTO
  3661.         Indicates that the socket should automatically power up sockets
  3662.         at card insertion time, if supported.
  3663.  
  3664.      SS_IOCARD
  3665.         Indicates that the socket should be configured for ``memory and
  3666.         IO'' interface mode, as opposed to simple memory card mode.
  3667.  
  3668.      SS_RESET
  3669.         Indicates that the card's hardware reset signal should be
  3670.         raised.
  3671.  
  3672.      SS_SPKR_ENA
  3673.         Indicates that speaker output should be enabled for this socket.
  3674.  
  3675.      SS_OUTPUT_ENA
  3676.         Indicates that data signals to the card should be activated.
  3677.  
  3678.   99..22..55..  SSSS__GGeettIIOOMMaapp,, SSSS__SSeettIIOOMMaapp
  3679.  
  3680.        int (*ss_entry)(u_int sock, SS_GetIOMap, pccard_io_map *);
  3681.        int (*ss_entry)(u_int sock, SS_SetIOMap, pccard_io_map *);
  3682.  
  3683.   The pccard_io_map data structure is given by:
  3684.  
  3685.        typedef struct pccard_io_map {
  3686.            u_char      map;
  3687.            u_char      flags;
  3688.            u_short     speed;
  3689.            u_short     start, stop;
  3690.        } pccard_io_map;
  3691.  
  3692.   The SS_GetIOMap and SS_SetIOMap entries are used to configure IO space
  3693.   windows.  IO windows are assumed to not support address translation.
  3694.   The Linux Card Services layer assumes that each socket has at least
  3695.   two independently configurable IO port windows.
  3696.  
  3697.   The map field specifies which IO map should be accessed.  The speed
  3698.   field is the map access speed in nanoseconds.  The start and stop
  3699.   fields give the lower and upper addresses for the IO map.  The flags
  3700.   field is composed of the following:
  3701.  
  3702.      MAP_ACTIVE
  3703.         Specifies that the address map should be enabled.
  3704.  
  3705.      MAP_16BIT
  3706.         Specifies that the map should be configured for 16-bit accesses
  3707.         (as opposed to 8-bit).
  3708.  
  3709.      MAP_AUTOSZ
  3710.         Specifies that the map should be configured to auto-size bus
  3711.         accesses in response to the card's IOCS16 signal.
  3712.  
  3713.      MAP_0WS
  3714.         Requests zero wait states, as opposed to standard ISA bus
  3715.         timing.
  3716.  
  3717.      MAP_WRPROT
  3718.         Specifies that the map should be write protected.
  3719.  
  3720.      MAP_USE_WAIT
  3721.         Specifies that access timing should respect the card's WAIT
  3722.         signal.
  3723.  
  3724.      MAP_PREFETCH
  3725.         Specifies that this map may be configured for prefetching.
  3726.  
  3727.   99..22..66..  SSSS__GGeettMMeemmMMaapp,, SSSS__SSeettMMeemmMMaapp
  3728.  
  3729.        int (*ss_entry)(u_int sock, SS_GetMemMap, pccard_mem_map *);
  3730.        int (*ss_entry)(u_int sock, SS_SetMemMap, pccard_mem_map *);
  3731.  
  3732.   The pccard_mem_map data structure is given by:
  3733.  
  3734.        typedef struct pccard_mem_map {
  3735.            u_char      map;
  3736.            u_char      flags;
  3737.            u_short     speed;
  3738.            u_long      sys_start, sys_stop;
  3739.            u_int       card_start;
  3740.        } pccard_mem_map;
  3741.  
  3742.   The map field specifies the map number.  The speed field specifies an
  3743.   access speed in nanoseconds.  The sys_start and sys_stop fields give
  3744.   the starting and ending addresses for the window in the host's
  3745.   physical address space.  The card_start value specifies the card
  3746.   address to be mapped to sys_start.  The Linux Card Services layer
  3747.   assumes that each socket has at least four independently configurable
  3748.   memory windows.
  3749.  
  3750.      MAP_ACTIVE
  3751.         Specifies that the address map should be enabled.
  3752.  
  3753.      MAP_16BIT
  3754.         Specifies that the map should be configured for 16-bit accesses
  3755.         (as opposed to 8-bit).
  3756.  
  3757.      MAP_AUTOSZ
  3758.         Specifies that the map should be configured to auto-size bus
  3759.         accesses in response to the card's IOCS16 signal.
  3760.  
  3761.      MAP_0WS
  3762.         Requests zero wait states, as opposed to standard ISA bus
  3763.         timing.
  3764.  
  3765.      MAP_WRPROT
  3766.         Specifies that the map should be write protected.
  3767.  
  3768.      MAP_ATTRIB
  3769.         Specifies that the map should be for attribute (as opposed to
  3770.         common) memory.
  3771.  
  3772.      MAP_USE_WAIT
  3773.         Specifies that access timing should respect the card's WAIT
  3774.         signal.
  3775.  
  3776.   99..22..77..  SSSS__GGeettBBrriiddggee,, SSSS__SSeettBBrriiddggee
  3777.  
  3778.        int (*ss_entry)(u_int sock, SS_GetBridge, cb_bridge_map *);
  3779.        int (*ss_entry)(u_int sock, SS_SetBridge, cb_bridge_map *);
  3780.  
  3781.   The cb_bridge_map data structure is given by:
  3782.  
  3783.        typedef struct cb_bridge_map {
  3784.            u_char      map;
  3785.            u_char      flags;
  3786.            u_int       start, stop;
  3787.        } cb_bridge_map;
  3788.  
  3789.   The SS_GetBridge and SS_SetBridge entry points are used for
  3790.   configuring bridge address windows for CardBus devices.  They are
  3791.   similar to the 16-bit IO and memory map services.  It is assumed that
  3792.   each CardBus socket has at least two IO and two memory bridge windows.
  3793.   The flags field is composed of:
  3794.  
  3795.      MAP_ACTIVE
  3796.         Specifies that the address map should be enabled.
  3797.  
  3798.      MAP_PREFETCH
  3799.         Specifies that this map can be configured for prefetching.
  3800.  
  3801.      MAP_IOSPACE
  3802.         Specifies that this map should be for IO space (as opposed to
  3803.         memory space).
  3804.  
  3805.   99..22..88..  SSSS__PPrrooccSSeettuupp
  3806.  
  3807.        int (*ss_entry)(u_int sock, SS_ProcSetup, struct proc_dir_entry *base);
  3808.  
  3809.   Card Services uses this entry point to give the socket driver a procfs
  3810.   directory handle under which it may create status files for a specific
  3811.   socket.  It is the socket driver's responsbility to delete any proc
  3812.   entries before it is unloaded.
  3813.  
  3814.   1100..  WWhheerree ttoo GGoo ffoorr MMoorree IInnffoorrmmaattiioonn
  3815.  
  3816.   The _L_i_n_u_x _K_e_r_n_e_l _H_a_c_k_e_r_s_' _G_u_i_d_e, written by Michael Johnson, is a good
  3817.   source of general information about writing Linux device drivers.  It
  3818.   is available from the usual Linux FTP sites, and is included in many
  3819.   compilations of Linux documentation.
  3820.  
  3821.   The genuine PC Card standard is only available from the PCMCIA
  3822.   association itself, and costs a significant amount of money.  To
  3823.   contact PCMCIA:
  3824.  
  3825.        Personal Computer Memory Card International Association
  3826.        1030 East Duane Avenue, Suite G
  3827.        Sunnyvale, CA 94086 USA
  3828.        (408) 720-0107, (408) 720-9416 FAX, (408) 720-9388 BBS
  3829.        http://www.pc-card.com
  3830.  
  3831.   One alternative is the _P_C_M_C_I_A _D_e_v_e_l_o_p_e_r_'_s _G_u_i_d_e, written by Michael
  3832.   Mori, available from Sycard Technology, ISBN 0-9640342-1-2, for
  3833.   approximately $89.95:
  3834.  
  3835.        Sycard Technology
  3836.        1180-F Miraloma Way
  3837.        Sunnyvale, CA 94086 USA
  3838.        (408) 749-0130, (408) 749-1323 FAX
  3839.  
  3840.   The _P_C_M_C_I_A _S_o_f_t_w_a_r_e _D_e_v_e_l_o_p_e_r_'_s _H_a_n_d_b_o_o_k by Dana Beatty, Steven
  3841.   Kipisz, and Brian Moore includes an overview of the PC Card standard,
  3842.   and descriptions of how to write client drivers.  It also includes the
  3843.   Linux PCMCIA Programmer's Guide, as an appendix.  It is published by
  3844.   Peer-to-Peer Communications, ISBN 1-57398-010-2.
  3845.   Larry Levine has written a more general introduction to PCMCIA called
  3846.   the _P_C_M_C_I_A _P_r_i_m_e_r.  It is published by M & T Books, ISBN
  3847.   1-55828-437-0.
  3848.  
  3849.   Programming information for various PC Card host controllers is
  3850.   available from the corresponding chip vendors.  Generally, data sheets
  3851.   are either available on line or can be ordered from each company's web
  3852.   site.
  3853.  
  3854.